Record Count for If Statement if 0

%3CLINGO-SUB%20id%3D%22lingo-sub-2395392%22%20slang%3D%22en-US%22%3ERecord%20Count%20for%20If%20Statement%20if%200%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2395392%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20written%20some%20code%20below%20to%20count%20if%20the%20SQL%20query%20I%20want%20to%20run%20has%20any%20records%20in%20it%20so%20I%20can%20use%20it%20in%20an%20if%20statement%20but%20can't%20get%20it%20to%20work.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDim%20lRecCount%20As%20Long%3CBR%20%2F%3ElRecCount%20%3D%20DCount(%22autonumber%22%2C%20%22Select_Unselected_StockWIP%22%2C%20%22(((Estimate_ID)%20%3D%20'%22%20%26amp%3B%20Me.EstimateNo%20%26amp%3B%20%22'%20And%20(Status)%3D0)%22)%3CBR%20%2F%3EMsgBox%20(lRecCount)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20get%20this%20error%20message%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22ajcbutler1120_0-1622202678748.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F284589iF25A8695A98837D3%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22ajcbutler1120_0-1622202678748.png%22%20alt%3D%22ajcbutler1120_0-1622202678748.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoes%20anyone%20know%20what%20I%20am%20doing%20wrong%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2395392%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAccess%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2395947%22%20slang%3D%22en-US%22%3ERe%3A%20Record%20Count%20for%20If%20Statement%20if%200%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2395947%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20is%20one%20opening%20parenthesis%20too%20many.%3C%2FP%3E%0A%3CP%3E(((Estimate_ID)%3C%2FP%3E%0A%3CP%3Ehas%20to%20be%3C%2FP%3E%0A%3CP%3E((Estimate_ID)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOr%20even%20better%2C%20leave%20out%20all%20superfluous%20parentheses%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ElRecCount%20%3D%20DCount(%22autonumber%22%2C%20%22Select_Unselected_StockWIP%22%2C%20%22Estimate_ID%20%3D%20'%22%20%26amp%3B%20Me!EstimateNo%20%26amp%3B%20%22'%20And%20Status%3D0%22)%3CBR%20%2F%3EMsgBox%20lRecCount%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EServus%3CBR%20%2F%3EKarl%3CFONT%20size%3D%22-1%22%3E%3CFONT%20face%3D%22Verdana%22%3E%3CBR%20%2F%3E*********%3CBR%20%2F%3E%3CA%20class%3D%22moz-txt-link-freetext%22%20href%3D%22http%3A%2F%2FAccessDevCon.com%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttp%3A%2F%2FAccessDevCon.com%3C%2FA%3E%3CBR%20%2F%3E%3CA%20class%3D%22moz-txt-link-freetext%22%20href%3D%22https%3A%2F%2Fwww.donkarl.com%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.donkarl.com%3C%2FA%3E%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
New 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