?
Solved

Numerical values in queries

Posted on 1999-07-23
4
Medium Priority
?
161 Views
Last Modified: 2010-04-30
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.
 
0
Comment
Question by:guyjj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 4

Expert Comment

by:siabod
ID: 1526878
Try this :

MyVar=30
"Select * from TableName where RecNum = " & MyVar
0
 

Accepted Solution

by:
jpforti earned 200 total points
ID: 1526879
Just try this :

Dim myVarNum as Integer
Dim myVarString as String
Dim sSQL as String
 

myVarNum = 30
myVarString = "Paul"

sSQL = "Select * from myTable Where myNum = " & CStr( myVarNum) & " and " & " Name = '" & myVarString & "'"


'Here is  you can submit the query
'be careful to not avoid the quote (') for a string !


0
 
LVL 2

Expert Comment

by:Pepster
ID: 1526880
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)
0
 

Author Comment

by:guyjj
ID: 1526881
Thanks for your immediate and very iluminating response. You guys are a good bunch to hang out with!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question