I am trying to count the number of records in a table that meet certain criteria. My preference is to use SQL, not Dcount, since I want to improve SQL. Here is my current code below:
Dim countString As String Dim count countString = "SELECT COUNT(*) FROM `Engagement Letters` WHERE 'Client ID' = " & Me.cboSelectClient count = CurrentDb.OpenRecordset(countString).Fields(0).Value
Yes, I know, I used spaces in my tables and field names - I will change that. Although I think that I still have to run this request as it is, so I will leave it as it is for now.
When I run above, I get a 3464 runtime error - data type mismatch in the criteria expression. I had the dcount function work below:
count = DCount("[Engagement Letter ID]", "Engagement Letters", "[Client ID] = " & Me.cboSelectClient)
And also the bottom COUNT query without WHERE works fine:
"SELECT COUNT(*) FROM `Engagement Letters`"
My knowledge of SQL is very minimal, and my knowledge of the more advanced VBA is also very minimal, so I'm not sure where I am going wrong. Can anyone help me with this?
source share