Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to execute stored query with parameters and "IN" clause? 1

Status
Not open for further replies.

vladk

Programmer
May 1, 2001
991
US
Hi,

Can anybody help me with "IN" clause parameters in a stored query?

My insert qryMyAmts query contains such a clause:
SQL:
WHERE MY_AMTKEY IN ('1','2','3')
It runs fine.

I want to call it from VBA in Access and I changed the clause to
SQL:
WHERE MY_AMTKEY IN ([MyAdmKeyList])

My VBA code is like this:

Code:
Dim qdf As DAO.QueryDef
Set qdf = CurrentDb.QueryDefs("qryMyAmts")
qdf.Parameters("MyAdmKeyList").value = strMyAdmKeyList
qdf.Execute

Where for strMyAdmKeyList I tried to assign this: "'1','2','3'" and this: "1,2,3".
In both cases the query inserts nothing. However, if the list contains just one value, it works.

May be somebody knows how to prepare such a parameter?

Thank you!

vladk


 
I'd try something like this:
Code:
Dim qdf As DAO.QueryDef
Dim strSQL As String
Set qdf = CurrentDb.QueryDefs("qryMyAmts")
strSQL = Replace(qdf.SQL, "[MyAdmKeyList]", strMyAdmKeyList)
DoCmd.RunSQL strSQL

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV,

Your advice works just fine!

Thank you so much!!!

vladk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top