Pass Parameter to Query in code (using IN function)

homer2002

Registered User.
Local time
Today, 10:11
Joined
Aug 27, 2002
Messages
152
Can I pass a parameter into a query using code

i have tried with this approach....


PUBLIC FUNCTION SomeCriterea() as string
SomeCriterea = "In('A',B','C')"
end FUNCTION


...and then in the criterea section of a query

SomeCriterea() (hoping this would put In('A',B','C') into the
criterea field


but it doesnt work ... however if i make the functions code

SomeCriterea = "='A'"

it works.

p.s. I really need it to be an IN statement as i am entering in many values to search on.

Thanks
 
In your query try in the criteria;
IN ([Parm1],[Parm2],[Parm3])
and supply the parms (you may have to play with that). But you maybe better served by just designing the query with out that criteria and then appending that criteria to the SQL in the query instead.
 
Thanks


Can I just append the SQL in a query then??

you see i'm creating on the fly querys, this time round the query may be an IN statement, but it could be somthing completly different next time.

I really need the values passed in this way.

(i also don't know how many paramaters would be passed in each time as the list in the IN statement comes from a multi select list box).
 
Try this:
Change the function to just return ('a','b','c') as a string.
In the query criteria cell, enter In SomeCriteria()

I think that will work.


Second idea:
make a table of criteria values,
insert rows from whatever source you want,
join the criteria table to whatever field you want in a query.

Run query.

For next use, delete all rows from criteria table, fill it again, run query again. Etc, Etc.

RichM
 

Users who are viewing this thread

Back
Top Bottom