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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Number Variable.

Status
Not open for further replies.

andrest

Programmer
Jul 25, 2002
20
CA
I'm trying to query a number variable to populate a listbox but no records are selected:

Dim stSQLString As String
Dim num as Integer
num = 2

stSQLString = "select * from emp where empno = '" & num & "'"

lstEmp.RowSource = stSQLString

Why is this not working?

Thanks.
 
Hiya,

You are attempting to insert a number into a string, and you are also terminating the string following the number.

It should be:

stSQLString = "select * from emp where empno = " & str(num)

which adds the number 2 (converted via STR) to the end of your stSQLString.

num = 2
str(num) = "2" (alphabetic not numeric)
"select * from emp where empno = " & "2"

equates to:

"select * from emp where empno = 2"

Regards,

Darrylle




"Never argue with an idiot, he'll bring you down to his level - then beat you with experience." darrylles@totalise.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top