General discussion

Locked

Easy 250 points - Passing a variable to

By haycoconsulting ·
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

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Easy 250 points - Passing a variable to

by SyscoKid In reply to Easy 250 points - Passing ...

Been awhile, but....

Dim empnum as Integer

OR

put empnum in quotes in the SQL statement


???

Collapse -

Easy 250 points - Passing a variable to

by haycoconsulting In reply to Easy 250 points - Passing ...

Tried both and neither work. Any other suggestions?

Collapse -

Easy 250 points - Passing a variable to

by Peyison In reply to Easy 250 points - Passing ...

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.

Collapse -

Easy 250 points - Passing a variable to

by haycoconsulting In reply to Easy 250 points - Passing ...

THANK YOU THANK YOU THANK YOU! IT WORKS!

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

Enjoy the points.

Collapse -

Easy 250 points - Passing a variable to

by haycoconsulting In reply to Easy 250 points - Passing ...

This question was closed by the author

Back to Software Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums