Link to home
Start Free TrialLog in
Avatar of guyjj
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.
 
Avatar of siabod
siabod

Try this :

MyVar=30
"Select * from TableName where RecNum = " & MyVar
ASKER CERTIFIED SOLUTION
Avatar of jpforti
jpforti

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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)
Avatar of guyjj

ASKER

Thanks for your immediate and very iluminating response. You guys are a good bunch to hang out with!