Query as filter for DoCmd.OpenForm - TechRepublic
General discussion
August 10, 2005 at 04:04 AM
p.w.d.stone

Query as filter for DoCmd.OpenForm

by p.w.d.stone . Updated 20 years, 11 months ago

Senario: Search form (carSearchAdvanced) uses query (qryCarSearch) to filter results for main display form (carDetails).

The search form (carSearchAdvanced) contains two combination boxes (cmbMake and cmbColour), the row source of which is another query grouping entries made in the table fields Make and Colour. This is done to avoid duplication where more than one car has the same make or colour.

If the option box (optMake) is selected, the following code is used to open the form carDetails (bound to the cars table)-

“If optMake.Value = True Then DoCmd.OpenForm “carDetails”, , “qryCarSearch”
End If”

This does open the form, but it always displays the first entry, and does not filter the results.

“SELECT Cars.FirstName, Cars.Surname, Cars.Make, Cars.Model, Cars.Colour, Cars.Registration, Cars.Type
FROM Cars
GROUP BY Cars.FirstName, Cars.Surname, Cars.Make, Cars.Model, Cars.Colour, Cars.Registration, Cars.Type
HAVING (((Cars.Make)=[Forms]![carAdvancedSearch]![cmbMake]) AND ((Cars.Colour)=[Forms]![carAdvancedSearch]![cmbColour]));”

I have tested the query- and doesn’t seem to be able to pull through the results of the combination boxes, presumably why the filter doesn’t work. Am I trying to do something impossible, or have I just got the syntax wrong?

This discussion is locked

All Comments