DCount Form Field ID

Thumper75

Registered User.
Local time
Today, 05:42
Joined
Feb 6, 2017
Messages
37
Hi Everyone. I have a form that displays all open work orders. I am trying to get a calculated filed to count the number of items on that work order using the dcount. The code looks right but it keeps displaying "#ERROR". I'm sure the mistake is in the parameters I am laying in but I'm not sure where.

I am attempting to put this code into the default value property for the field.


=DCount("[ID]","TBLAcft_Desc","[N_Number] = '" & [Forms]![frm_WO_Cont]![txt_tail] & "'")
 
Put expression in ControlSource, not DefaultValue.

Is N_Number a text field?

Or maybe have a subform for the items and use Count(*)
 
Last edited:
if N_Number is a numeric datatype, your criteria/where parameter should not include the single quotes

"[N_Number] = " & [Forms]![frm_WO_Cont]![txt_tail]

and if the control is in frm_WO_Cont you use the me. predicate instead

"[N_Number] = " & me.txt_tail
 
Me. only works in VBA, not in textbox.

If both controls are on frm_WO_Cont, simply:

=DCount("[ID]","TBLAcft_Desc","[N_Number] = '" & [txt_tail] & "'")
 
This is the code that I entered into the Default Value property field.

=DCount("[ID]","TBLAcft_Desc","[Visit] = '" & [txt_visit] & "'")

It still returns #ERROR on the field list. Is it possible I am putting this in the wrong property?

Perhaps it would be helpful to mention that the form lists multiple records.
 
Last edited:
as June said in post#2 - you put it in the controlsource
 
I put it in control source and still getting the #ERROR.

The code looks correct.......
Code:
=DCount("[ID]","TBLAcft_Desc","[Visit] = '" & [txt_visit] & "'")

I have it in the Control Source property of the field.
 
what is the datatype for your visit field? If numeric, see post #3
 
Ok I'm not sure what happened but it is now returning values.
 
Ok I'm not sure what happened but it is now returning values.
You might have made design view changes, then put the form in form view without saving first. I have seen this behaviour produce this result. Save the form in design view, go to form view and the problem disappears.
 

Users who are viewing this thread

Back
Top Bottom