SQL Select Statement passing value from a form

  • Thread starter Thread starter Jim Pockmire
  • Start date Start date
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;"
 
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;"
 
Back
Top