View Single Post
  #6  
Old January 30th, 2009, 04:35 AM posted to microsoft.public.access.queries
MGFoster
external usenet poster
 
Posts: 653
Default help using a parameter in an 'In (...)' criteria

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Switch to SQL view.

At the top of the screen, before SELECT, put the PARAMETERS clause:

PARAMETERS parSurveyList Text, the other parameter names and data
types. Don't enter the angle brackets. End the clause with the semi
colon. ;
SELECT ...
FROM ...

NB: qdf.Parameters(0) is the first parameter in the PARAMETERS list, so
always use the parameter name when assigning values to parameters - this
will avoid errors.

You're correct about the square brackets, but you're putting them in the
wrong place. Should be like this:

WHERE InStr("," & parSurveyList & ",", "," & [SurveyType] & ",")0

other criteria

Don't put quotes around the parameter name, nor the column name
(SurveyType).

When you work in the Design Grid, Access "helpfully" places quotation
marks around just about everything! That's why I work a lot in the SQL
View.

--
MGFoster:::mgf00 at earthlink decimal-point net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSYKDf4echKqOuFEgEQIEnACdFd5KD+6a21VP/yqqnFHH/Q6xfYIAoMIL
pR2Sa3W2EyB0pGjVH0eFARXq
=V4tz
-----END PGP SIGNATURE-----

Jey wrote:
Hi,

I can't get it to work!?! In the code I have:
strSurveyList = "2,3"
qdf.Parameters("parSurveyList") = strSurveyList

But I get an error when the code hits the qdf.Parameters... line, because
the query isn't asking for [parSurveyList].

In the query when I put InStr("," & "parSurveyList" & ",","," & "SurveyType"
& ",") 0 as a criteria for the field SurveyType, table Survey... after
saving & closing the query when I re-open it the field is now InStr("," &
"parSurveyList" & ",","," & "SurveyType" & ",") and the criteria is 0.

Shouldn't I have [parSurveyList] (in square brackets) somewhere so it knows
to ask for that parameter??
When I change the field to InStr("," & [parSurveyList] & ",","," &
"SurveyType" & ",")
it runs, but doesn't return the counts I'd expect if it was working right,
just nulls.

Jey