SQL Select Statement passing value from a form

J

Jim Pockmire

I am trying to open a recordset using a SQL statement that contains a value
from an open form in the WHERE clause. I am getting an error "expecting 2
parameters".

strSQL = "SELECT [USER_CODE] FROM SYSADM_APP_SECURITY WHERE ([USER_CODE] >=
[Forms]![AdvanSec RptsFrm]![FromUser] And [USER_CODE] <= [Forms]![AdvanSec
RptsFrm]![ToUser]) WITH OWNERACCESS OPTION;"
 
A

Allen Browne

Concatenate the values from the form into the string:

strSQL = "SELECT [USER_CODE] FROM SYSADM_APP_SECURITY " & _
"WHERE ([USER_CODE] >= """ & [Forms]![AdvanSec RptsFrm]![FromUser] & _
""" ) And ([USER_CODE] <= """ & [Forms]![AdvanSec RptsFrm]![ToUser] & _
""") WITH OWNERACCESS OPTION;"

Remove the extra quotes if User_Code is a Number field (not a Text field.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Jim Pockmire said:
I am trying to open a recordset using a SQL statement that contains a value
from an open form in the WHERE clause. I am getting an error "expecting 2
parameters".

strSQL = "SELECT [USER_CODE] FROM SYSADM_APP_SECURITY WHERE ([USER_CODE]
= [Forms]![AdvanSec RptsFrm]![FromUser] And [USER_CODE] <=
[Forms]![AdvanSec RptsFrm]![ToUser]) WITH OWNERACCESS OPTION;"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top