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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Andrew Fergus

MrExcel MVP
Joined
Sep 9, 2004
Messages
5,452
Office Version
  1. 365
  2. 2021
  3. 2016
Platform
  1. Windows
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
 

jeffmoseler

Well-known Member
Joined
Jul 16, 2004
Messages
540
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!
 

Marbles

Well-known Member
Joined
Feb 7, 2005
Messages
626
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?
 

Marbles

Well-known Member
Joined
Feb 7, 2005
Messages
626
No it wouldn't, sorry.
 

Marbles

Well-known Member
Joined
Feb 7, 2005
Messages
626
This one instead:

=DCount(" [ENGINE_TYP]","Boats"," [ENGINE_TYP]='OU' And [No_Berths]=2")
 

Andrew Fergus

MrExcel MVP
Joined
Sep 9, 2004
Messages
5,452
Office Version
  1. 365
  2. 2021
  3. 2016
Platform
  1. Windows
Hi Jeff

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

Andrew
 

jeffmoseler

Well-known Member
Joined
Jul 16, 2004
Messages
540
DOh... I figured it out. One of my controls had bad syntax, but I couldn't see it because it was hidden! Thanks guys!
 

Forum statistics

Threads
1,181,055
Messages
5,927,858
Members
436,573
Latest member
CMR237

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
Top