Discussion Locked

Easy 250 points - Passing a variable to

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

What is the d*** syntax to pass a variable to an SQL statement.

For example:

I want to know the number of records that exist in the RollCallData table for an employee number entered into Text1

empnum = Text1.value

SELECT * FROM tblRollCallData WHERE EmployeeNumber = empnum;

I can make it work if I enter the employee number directly in the SQL statement, but I can't seem to pass the variable 'empnum' to the SQL statement

Should be an easy 250 points for somebody.

Thanks

5 replies

by syscokid

Been awhile, but....

Dim empnum as Integer

OR

put empnum in quotes in the SQL statement

???

by peyison

Are you doing this in Access? And this is code in a code module? (i.e. the select statement is not in the row source property of a list box, or something like that). If this is in code, you need to do string concatenation to create the select statement:

sSql = "Select * From tblRollCallData Where EmployeeNumber = " & empnum & ";"

You can set a breakpoint after the select statement and do a quick watch to see what empnum and sSql are actually being set to.

Hope this helps.

by haycoconsulting

THANK YOU THANK YOU THANK YOU! IT WORKS!

Peyison, YOU DA MAN! (or DA PERSON as the case may be)

Enjoy the points.

This discussion is closed to new replies.