Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DCount making me go insane! - please help 1

Status
Not open for further replies.

Jayz

ISP
Feb 17, 2002
59
Ok,
I'm obviously doing something wrong here, I can't get this to work.

I have a query named [qryBacklog] and a field name
Code:
 which displays letters A-F depending on days elapsed for the total days an order is overdue. eg >100 days =A, >80days=C and so on...

I created my continuous form based on the query. and created an unbound text box. In the control source I entered:

=DCount("[code]","qryBacklog","[Code] = 'A'")

This is suppose to count the Number of times the letter "A" appears, but instead I get the #Error.

What am I doing wrong.

Please help.

Regards,
Jay
 
The first argument in the DCount function is NOT optional, you have to have a value here, in your example, you do not. This represents the field that you want to count.

If the name of your field is Field1, then the DCount function should look like this:

=DCount("Field1", "qryBackLog", "Field1='A'") Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
 
Hi Jim,

This is the code I applied:

=DCount("code","qryBackLog","code='A'")

My field name is
Code:
, I'm still getting that #Error.

Any suggestions why?

Thanks,
Jay
 
my field name is code. I don't know why Tek-Tips converts it to that funny character.
 
Your syntax is correct. Try opening the debug window (ctrl+g) and typing in

?DCount("code","qryBackLog","code='A'")

and hit enter. See if the number comes back correctly. Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
 
Would this have anthing to do with the field "code" being created in the query grid and not actually existing in a table.

eg. The field Code in the query grid has been created:

Code:IIf([Elapsed]>=100,"A",IIf([Elapsed]>=81,"B",IIf([Elapsed]>=61,"C",IIf([Elapsed]>=41,"D",IIf([Elapsed]>=21,"E","F")))))

Any help please??
 
Hi Jim,
Thanks for taking out the time to look at this.

I ran the code in the debug window and it came up with this error message:

Run-time error '62506':
Data type mismatch in criteria expression

What does this mean?

 
Actually, why don't you just create a function, and use it instead:

Put this in a module, replace the red part with the name of the table the Elapsed field is in.

=====
Public Function GetACount() As Long
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("SELECT Count(Elapsed) AS TotCount FROM TableNameHere WHERE Elapsed>=100", dbOpenSnapshot)
GetACount = rs!TotCount
rs.Close
Set rs = Nothing
End Function
=====

Now in your text box, instead of using the DCount, put this:

=GetACount()
Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
 
Perfect!!!!,

Thanks Jim for all your patience and help. Keep up the good work.


Regards,
Jay
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top