Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable use in sql where statement

Status
Not open for further replies.

GTO

Programmer
Jul 11, 2000
40
0
0
US
I want to use a bar code readout in a variable as the
= 'variable';) in the where part of a sql statement.
I just can't seem to get this to work. It doesn't appear to see the variable. It only sees hard coded info. Does anyone know how to make this work?
 
If it's text you'll have to add quotes by hand...
Can you post a code snippet?
 
Like hbaake says if it is text you will need quotes so the statement in code should be something like

sql= "Select * From table where " & chr(39)& {variable} & chr(39)

chr(39) is the ascii code for a single qoute



other types of data require different handling ie dates require # before and after when using jet sql.

hope this helps
sdh
::)
 
Dim sBarScan as String
Dim sSQL as StrIng

sBarScan = incoming data from scanner
sSQL = "SELECT * FROM TABLE WHERE FIELD='" & sBarScan & "'"
 
Thanks a lot guys. Turns out that I didn't know the correct syntax for the variable. I ended up using woyler's example to get this;

rs.Open ("SELECT ItemDescription, Amount from DeptInfo where Identifier = '" & sBarScan & "'")

Again, thanks to all who responded.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top