Link to home
Start Free TrialLog in
Avatar of Evert Jor
Evert JorFlag for Norway

asked on

How do I refer to a session variable in a query?

I want to use the session variable "clientuser" as a criteria in a query, but can't get it to work. The variable is a number. My query looks like:

strSQL5 = "SELECT TOP 50 Varenr, Varetekst, SumAvAntall FROM tbl_Hstat WHERE Kundenr =<%SESSION("clientuser")%> ORDER BY tbl_Hstat.SumAvAntall DESC;"

Any idea what is wrong? Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Scott McDaniel (EE MVE )
Access doesn't use Session Variables. Where are you expecting to get the Session variable from? Most commonly you find Session variables in web-based programming.
Avatar of Evert Jor

ASKER

I got it working with this (had to remove the ' ):

strSession = SESSION("clientuser")
strSQL5 = "SELECT TOP 50 Varenr, Varetekst, SumAvAntall FROM tbl_Hstat WHERE Kundenr = " & strSession & " ORDER BY tbl_Hstat.SumAvAntall DESC "

And to Scott: Yes, it is web programming with Access as the database. The session variable is used to limit the results to a specific users dataset.
Works without the '