Hi, and thanks in advance for any help on my question.
I have a search form Named QS that is based on a query.
It displays the following fields:
Name, Building, Floor, Apartment, Gender, Age (age field is created by calling a public function that calculates the age from Date of Birth)
In my search form I have unbounded combo boxes and text boxes for the user to choose options that will be the criteria for multiple filter searches.
The combo boxes are named cboBuild, cboFloor, cboApt, cboGen
The text boxes are txtFrom, txtTo which values I use as range for searching by age
Using the combo boxes, the user is able to filter by multiple criterias: for example:
list of all the women that live in a building in a specific floor. and apartment.
list of all the men that live in a specific building
list of all the persons that live in a specific apartment
Using the text boxes, the user can list of all the persons that are within a range of age.
In the AfterUpdate event of the combo boxes I wrote the following code to filter by building, floor, apartment and gender:
DoCmd.ApplyFilter "([Building]=[Forms]![QS]![cboBuild] Or [Building]=[Forms]![QS]![cboBuild] Is Null) And" & _
"([Floor]=[Forms]![QS]![cboFloor] Or [Floor]=[Forms]![QS]![cboFloor] Is Null) And" & _
"([Apartment]=[Forms]![QS]![cboRom] Or [Apartment]=[Forms]![QS]![cboRom] Is Null) And" & _
"([Gender]=[Forms]![QS]![cboGen] Or [Gender] = [Forms]![QS]![cboGen] Is Null)"
In the AfterUpdate of txtTo I wrote the code following code to search by age.
Dim filAge as string
filAge = "([Age] >= " & Me.tFra & " And [Age]<= " & Me.tTil & ")"
DoCmd.ApplyFilter , filAge
Age is a calculated field generated in the query. The calculation of Age is done in a public function from Date of Birth value.
Both of the upper filters work well independently.
I tried to combine both filters by adding the Age criteria to the end of the list of the other criterias, but it doesn't work.
DoCmd.ApplyFilter "([Building]=[Forms]![QS]![cboBuild] Or [Building]=[Forms]![QS]![cboBuild] Is Null) And" & _
"([Floor]=[Forms]![QS]![cboFloor] Or [Floor]=[Forms]![QS]![cboFloor] Is Null) And" & _
"([Rom]=[Forms]![QS]![cboRom] Or [Rom]=[Forms]![QS]![cboRom] Is Null) And" & _
"([Gender]=[Forms]![QS]![cboGen] Or [Gender] = [Forms]![QS]![cboGen] Is Null)" & _
"([Age] >= " & Me.tFra & " And [Age]<= " & Me.tTil & ")"
My guess is that it is not working because Age is a calculated field generated from the query. But I don't if that is the reason, and I dont know how to write the code to add the age filter to the rest of the criteria.
How to I correct my code for Age to be a part of my multiple filter criterias?
Best regards.