Using textbox value for DCount() #Error

Zc kaiva

New member
Local time
Today, 09:04
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?
 
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:

 
=Dcount("[BusNo]","qryBus","[RegDate]=#" & txtBox & "#")
 
=Dcount("[BusNo]","qryBus","[RegDate]=#" & Format$([Text1], "mm\/dd\/yyyy") & "#")
 
=Dcount("[BusNo]","qryBus","[RegDate]=#" & Format$([Text1], "mm\/dd\/yyyy") & "#")

I tried it but it keeps givim 0 as count.
 
does [RegDate] has "time" element in it?
 
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

Back
Top Bottom