Record Count for If Statement if 0

Copper Contributor

Hi

 

I have written some code below to count if the SQL query I want to run has any records in it so I can use it in an if statement but can't get it to work.

 

Dim lRecCount As Long
lRecCount = DCount("autonumber", "Select_Unselected_StockWIP", "(((Estimate_ID) = '" & Me.EstimateNo & "' And (Status)=0)")
MsgBox (lRecCount)

 

I get this error message:

 

ajcbutler1120_0-1622202678748.png

 

 

Does anyone know what I am doing wrong?

 

1 Reply

Hi,

 

There is one opening parenthesis too many:

(((Estimate_ID)

has to be

((Estimate_ID)

 

Or even better, leave out all superfluous parenthesis:

 

lRecCount = DCount("autonumber", "Select_Unselected_StockWIP", "Estimate_ID = '" & Me!EstimateNo & "' And Status=0")
MsgBox lRecCount

 

Servus
Karl
*********
http://AccessDevCon.com
https://www.donkarl.com