DataType Mismatch error

  • Thread starter Thread starter GACarGuy
  • Start date Start date
G

GACarGuy

I'm missing something really simple but I don't see. When I run the code
below I am getting a data mismatch error on the last execute statements.

Function WorkListBuild()
'Route Variables
Dim b As Integer
b = 15

'This line Works
Set rs = cn.Execute("SELECT COUNT(lacct) From tblWorkLists WHERE
DaysPastDue = 15 ")

'This line does not,
Set rs = cn.Execute("SELECT COUNT(lacct) From tblWorkLists WHERE
DaysPastDue = b ")

End Function


Thanks for the help
 
I'm missing something really simple but I don't see. When I run the code
below I am getting a data mismatch error on the last execute statements.

Function WorkListBuild()
'Route Variables
Dim b As Integer
b = 15

'This line Works
Set rs = cn.Execute("SELECT COUNT(lacct) From tblWorkLists WHERE
DaysPastDue = 15 ")

'This line does not,
Set rs = cn.Execute("SELECT COUNT(lacct) From tblWorkLists WHERE
DaysPastDue = b ")

End Function

You need to concatenate the *value* of the variable into the query, not its
name. The JET query engine doesn't know anything about VBA variables. Try

Set rs = cn.Execute("SELECT COUNT(lacct) From tblWorkLists WHERE
DaysPastDue = " & b )
 
Back
Top