Using textbox value for DCount() #Error (1 Viewer)

Zc kaiva

New member
Local time
Today, 07:27
Joined
May 9, 2021
Messages
9
I have a textbox 'Text1' which stores date value entered as report parameter on my report. When u use it with dcount() as criteria it gives me #error. This is what i have.

=Nz(Dcount("[BusNo]","[qryBus]","[qryBus].[RegDate]=[Text1]"),0)

Can anyone help me find my mistake?
 

plog

Banishment Pending
Local time
Today, 01:27
Joined
May 11, 2011
Messages
11,643
1. Dcount will never return null, so Nz() is not needed.
2. You don't need to reference the query in the criteria argument.
3. You need to escape out of the criteria string to insert the date from the form.
4. You must use escape characters around the date value in the criteria.

Check out this post with very similar issue:

 

Ranman256

Well-known member
Local time
Today, 02:27
Joined
Apr 9, 2015
Messages
4,337
=Dcount("[BusNo]","qryBus","[RegDate]=#" & txtBox & "#")
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:27
Joined
May 7, 2009
Messages
19,230
=Dcount("[BusNo]","qryBus","[RegDate]=#" & Format$([Text1], "mm\/dd\/yyyy") & "#")
 

Zc kaiva

New member
Local time
Today, 07:27
Joined
May 9, 2021
Messages
9
=Dcount("[BusNo]","qryBus","[RegDate]=#" & Format$([Text1], "mm\/dd\/yyyy") & "#")

I tried it but it keeps givim 0 as count.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:27
Joined
May 7, 2009
Messages
19,230
does [RegDate] has "time" element in it?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:27
Joined
Feb 19, 2002
Messages
43,257
Formatting isn't necessary unless the control is unbound AND does not have a format property that indicates it will be a date.

PS - if Text1 is really the name of the control, you might want to rename the control to give it a meaningful name before you add any event procedures or references that use the poor name.
 

Users who are viewing this thread

Top Bottom