Evert Jor
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.
strSQL5 = "SELECT TOP 50 Varenr, Varetekst, SumAvAntall FROM tbl_Hstat WHERE Kundenr =<%SESSION("clientuser")%>
Any idea what is wrong? Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
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.
ASKER
Works without the '