Using IN criteria with parameter queries

T

Toxalot

Access 2003

I want to use a parameter query using IN criteria rather than equal
criteria.

SELECT lngPersonId FROM tblProfilePeople WHERE intRoleId IN
([prmintRoleId]);

If I enter an integer at the prompt it works, but I want to enter more
than one integer. I can do the following in a regular query.

SELECT lngPersonId FROM tblProfilePeople WHERE intRoleId IN (1,2);

I know the above could also be written as
SELECT lngPersonId FROM tblProfilePeople WHERE intRoleId = 1 OR
intRoleId = 2;

But it won't always be just one OR. KWIM?

Can I get this to work in a parameter query?

Jennifer
 
S

Stefan Hoffmann

hi,
SELECT lngPersonId FROM tblProfilePeople WHERE intRoleId IN
([prmintRoleId]);
If I enter an integer at the prompt it works, but I want to enter more
than one integer. I can do the following in a regular query.
Can I get this to work in a parameter query?
Aircode:

--
Option Compare Database
Option Explicit

Public Function QueryIn(AField As Variant, _
AParameters As String _
) As Boolean

'AParameters must be comma-delimited.

Dim Count As Long
Dim Parameters() As String
Dim Result As Boolean

Parameters() = Split(AParameters, ",")
Result = False

For Count = LBound(Parameters) To UBound(Parameters())
Result = (AField = Parameters(Count))
If Result Then
Exit For
End If
Next Count

QueryIn = Result

End Function
--

Use

SELECT lngPersonId
FROM tblProfilePeople
WHERE QueryIn(intRoleId, [QueryForParam]);

mfG
--> stefan <--
 

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