Dcount Multiple Criteria Syntax (1 Viewer)

Drand

Registered User.
Local time
Today, 13:45
Joined
Jun 8, 2019
Messages
179
Hi

Could someone please help me with this. I have tried so many variations with syntax and just cannot get it right!

My stripped down Dcount statement looks like:
Code:
RecordExists = Dcount("ID","tblStockOut",StockItem = & StockItem & and Quantity = & Quantity & and Date = & ThisDate &)

Where all three are variables.

StockItem is a string
Quantity is an Integer
Date is a date

Would appreciate if someone could show me exactly where all the punctuation etc. goes in this.

Many Thanks
David
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:45
Joined
May 7, 2009
Messages
19,245
try:

RecordExists = Dcount("ID", "tblStockOut" ,"StockItem = '" & StockItem & "' and Quantity = " & Quantity & " and [Date] = " & Format(ThisDate, "\#mm\/dd\/yyyy\#" ))
 

Drand

Registered User.
Local time
Today, 13:45
Joined
Jun 8, 2019
Messages
179
Thank you. Works perfectly.

I have googled this many times without success.

Is there a reference point where I can learn this?
 

Gasman

Enthusiastic Amateur
Local time
Today, 04:45
Joined
Sep 21, 2011
Messages
14,310
Strings need to be surrounded by single quotes ' unless it contains a single quote, then triple double quotes works, I think?

Date literals with # and in mm/dd/yyyy or yyyy-mm-dd format

Numbers do not need anything

Also for anything other than one item of criteria, I tend to put the the criteria into a string variable and then debug.print it, until correct then also use that in the function.

Added benefit is, if you still cannot see the error, you can copy and paste back here for someone else to spot it. :)
 

Users who are viewing this thread

Top Bottom