DCount Form Field ID (1 Viewer)

Thumper75

Registered User.
Local time
Today, 03:46
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] & "'")
 

June7

AWF VIP
Local time
Today, 00:46
Joined
Mar 9, 2014
Messages
5,493
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:

CJ_London

Super Moderator
Staff member
Local time
Today, 09:46
Joined
Feb 19, 2013
Messages
16,670
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
 

June7

AWF VIP
Local time
Today, 00:46
Joined
Mar 9, 2014
Messages
5,493
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] & "'")
 

Thumper75

Registered User.
Local time
Today, 03:46
Joined
Feb 6, 2017
Messages
37
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:

CJ_London

Super Moderator
Staff member
Local time
Today, 09:46
Joined
Feb 19, 2013
Messages
16,670
as June said in post#2 - you put it in the controlsource
 

Thumper75

Registered User.
Local time
Today, 03:46
Joined
Feb 6, 2017
Messages
37
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.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 09:46
Joined
Feb 19, 2013
Messages
16,670
what is the datatype for your visit field? If numeric, see post #3
 

Thumper75

Registered User.
Local time
Today, 03:46
Joined
Feb 6, 2017
Messages
37
Ok I'm not sure what happened but it is now returning values.
 

Micron

AWF VIP
Local time
Today, 04:46
Joined
Oct 20, 2018
Messages
3,478
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

Top Bottom