View Full Version : Question about Querying fields in queries


Alycia
04-27-2004, 08:34 AM
I have a table with quite a few yes/no fields. I want to create a query that allows a user to plug in the name of one of those fields and all of the "yes" responses are returned. I'd prefer not to have the user have to go through multiple queries to find the particular field needed. Does anyone know how to do this?

RichO
04-27-2004, 10:18 PM
The only way I can think of doing this involves a form, a query, and a report.

Set up a combo box on a form, use the wizard (I will type in the values...) and then enter the exact names of all the Yes/No fields in the table. Name this combo box cboField.

Design a simple query selecting * (all fields).

Design a report using the wizard, use the above query as the record source.

Now back your form, set up a command button using the wizard, select Preview Report as your option. Once the button is created, go to the event tab of the command button properties and click to the right of the [Event Procedure] box and the code window will open.

Where it says DoCmd.OpenReport, right after acPreview, enter the following:

, , "[" & cboField & "] = True "

Take note that there are 2 commas before the criteria expression (very important).

Now you should be able to select a field by name, click the button and a report will open showing all records where that field contains a Yes.

Hope it works for you.

Mile-O
04-28-2004, 02:45 AM
Set up a combo box on a form, use the wizard (I will type in the values...) and then enter the exact names of all the Yes/No fields in the table. Name this combo box cboField.

This would be made all the easier if the data were normalised - a number of checkboxes, to me, sounds like a repeating group.