View Full Version : Help Needed passing form parameters


Gallma02
05-29-2002, 04:30 AM
I am attempting to have a form which can pass a number of parameters to a single query depending on what is selected. Therefore I added in the criteria line of the query design the line, [Forms]![Investment Report Selection]![Text5] which works perfectly when I pass a specific value in the Text5 field. My problem arises that if no selection is made I want to retrieve all the records.

I have tried using the wildcard “*”, I found that when I passed it from a form text box the query SQL adds a = in front of it, so the query literally looks for “*” and therefore retrieves no rcords.

Could anyone tell me how to retrieve all the records from a query when using a text field of a form as a selection criteria.

Hayley Baxter
05-29-2002, 05:19 AM
I use this in one of my dbs. All I did was

Like *

and that returned all records for me.

Hayley

Gallma02
05-29-2002, 05:47 AM
Thanks Hayley, unfortunately I have tried Like * with no luck. I have tried a number of combinations using Like, *, ! but nothing will return all the records when entered as a parameter and sent to the query criteria.

Fornatian
05-29-2002, 07:23 AM
Your parameter should look like:

Like "*" & Me!MyForm!MyField & "*"

Essentialy it concatanates it all together for parsing so you end up with:

Like "*FindMe*"

Gallma02
05-29-2002, 10:57 PM
Thanks Fornation, I will try this method. Otherwise I have found a solution while looking through some old queries on the site. On the 28/10/2000, R Hicks posted this solution which I have tested and meets my requirements perfectly.

The following was a solution provided by R Hicks for the Topic: Parameter Query with "*" as an option,
"Let's say you have a field in the query named "PartNumber" and you want to use this as the criteria for the query. You want an input box with the message "Enter Part Number".

The following will happen:
If you enter part number, the query will return the record containing the part number entered.
If you leave the input box empty (blank), and click "OK", the query will return all records.

Here's how to do it:
The trick is place [Enter Part Number] in the second line (not the first line) of the criteria of the PartNumber field.
Now in an empty field place Exp1:[Enter Part Number] as the field name. Now in the first criteria line of this added field put Is Null, in the second criteria line put Is Not Null."