help using a parameter in an 'In (...)' criteria
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
You can use the InStr() trick:
1. Set up a Public function in the criteria form that passes a comma
delimited string of the parameters. If there aren't any parameters the
function should return zero (see below). If the function is passing
comma-delimited strings be sure to use single quotes - like this:
FunctionName = "'abcd', 'efghi', 'xyz'"
2. Set up the query to read that Public function:
PARAMETERS Forms!FormName!FunctionName Text(255);
....
3. Set up the WHERE clause with something like this:
IIf(Forms!FormName.FunctionName="0",True,InStr("," &
Forms!FormName.FunctionName & ",","," & column_name & ",")0)
Substitute the correct column name that holds the data for which you
want to search for "column_name."
An english translation of the above: If the function returns 0 then use
"True" as a default for this expression. Otherwise, use the InStr()
trick to determine if any of the comma-delimited parameters are in the
"column_name" column.
--
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/AwUBSX9lOIechKqOuFEgEQLu/gCgpV4yAEdxNI6gOMuwPPjXsl/6iGoAoIPm
LXfTZlg2g7qOfG3ZAvYt1bix
=nc4N
-----END PGP SIGNATURE-----
Jey wrote:
I have a series of queries that all have the same criteria: "In (2,3)" (plus
a few others). They are being called from VBA code, where the parameters are
generated and passed to the queries. I want the "In" criteria to be passed as
a parameter, since the list may not be '2,3' in every case. I can't seem to
make it work!
I've tried putting '[parameter]' as the criteria and passing 'In (2,3)' to
it, but I get an error message saying the expression is too complicated.
I've tried putting 'In ([parameter])' as the criteria and passing '2,3' to
it, but it doesn't return any records.
Any suggestions? Thanks in advance,
Jey
|