guyjj
asked on
Numerical values in queries
I have two variables that I would like to use to select records in a query. One of them is a string variable (e.g., strName) and the other is a number (e.g.,RecNum). I can get the following to work: "Select * from TableName where name = '" & strName & "'". I can also get results with "Select * from TableName where RecNum = (for example)30". What I cannot figure out is how to get the proper syntax using the variable RecNum rather than a specific numerical value.
Please help.
Please help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
As you are passing a query to a recordset via a string you have to pass the numerical value as a string so:
qry = "SELECT * FROM TableName WHERE RecNum = " & _
str(RecNum)
qry = "SELECT * FROM TableName WHERE RecNum = " & _
str(RecNum)
ASKER
Thanks for your immediate and very iluminating response. You guys are a good bunch to hang out with!
MyVar=30
"Select * from TableName where RecNum = " & MyVar