What's wrong with this expression?

jeffmoseler

Well-known Member
Joined
Jul 16, 2004
Messages
540
This is what I have:

=DCount("[Printed]![PartNumber] ","Printed","Printed!PartNumber= [ItemOnlyFormTex2] And Printed!SalesOrder = [SalesOrderNumFormTex2] ")

It isn't working and I'm not sure why. I know it's a syntax thing, and I know it has to do with the AND, but I don't know what I am doing wrong. What suggestions do you have?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi Jeff

I haven't test this but try this:

Code:
=DCount("[PartNumber]","Printed","[PartNumber] = '" & [ItemOnlyFormTex2] & "' And [SalesOrder] = '" & [SalesOrderNumFormTex2] & "'")

If 'ItemOnlyFormTex2' exists on a form, then you may need to set it up like this instead:
Forms![YourFormName].[ItemOnlyFormTex2]

Repeat for the 'SalesOrderNumFormTex2' part.

HTH, Andrew
 
Upvote 0
Thanks Andrew,
It is still not working even after I ended up with this:

=DCount("[PartNumber]","Printed","Table!Printed![PartNumber] = '" & Forms!PrintTravelerForm.ItemOnlyFormTex2 & "' And Tabel!Printed![SalesOrder] = '" & Forms!PrintTravelerForm.SalesOrderNumFormTex2 & "'")


Here's a hint:

=DCount("[Printed]![PartNumber] ","Printed","Printed!PartNumber= [ItemOnlyFormTex2]")

The above works fine. It counts all the records that match the PrintedPartNumber to the control on the form. But when I add the AND it shows an error. I can tell you that both the SalesOrderNumFormTex2 and the ItemOnlyFormTex2 are controls on the form. I can also tell you the fields in the table are both formatted as text.

Thanks so much for the help Andrew!
 
Upvote 0
I've tried this with a table, and it seems to work:

=DCount(" [ENGINE_TYP]","Boats"," [ENGINE_TYP]='OU'")+DCount(" [ENGINE_TYP]","Boats"," [ENGINE_TYP]='Pe'")

Would that help?
 
Upvote 0
This one instead:

=DCount(" [ENGINE_TYP]","Boats"," [ENGINE_TYP]='OU' And [No_Berths]=2")
 
Upvote 0
Hi Jeff

The format of the two fields on the form - are they text or numbers?

Andrew
 
Upvote 0
DOh... I figured it out. One of my controls had bad syntax, but I couldn't see it because it was hidden! Thanks guys!
 
Upvote 0

Forum statistics

Threads
1,213,517
Messages
6,114,089
Members
448,548
Latest member
harryls

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top