jj***********@yahoo.com wrote:
Newbie needing some help. I have a tblParticipants. The fields
include gender, education_level, income, occupation etc., I'm trying to
create a form where a user can run a query from the form and just
choose the appropriate criterias from the combo boxes to get the
results. I also want the query to run even if there is not a value in
all the combo boxes ie., i want just all males with income level of
over $100,000...Any insights or help would be greatly appreciated.
Thanks.
I would create your combo boxes that will filter your record selection.
I assume you know how to create the combo boxes and supply the data.
I also assume you can do a little bit of vba coding.
Higlight all the combos for filtering, select the AfterUpdate event row
and enter
=MakeFilter()
Create a command button to reset the filter. This will clear out the
combo boxes and display all records. In the OnClick event, click on the
triple dot at end of row, select EventProcedure, and enter something like
Dim blnOK As Boolean
Me.ComboGender = Null
Me.ComboIncome = Null
'...null out rest of combos
blnOK = MakeFilter()
Now create your MakeFilter function. Create your filter with a series
of IF statements
Private Function MakeFilter() As Boolean
'if you are using string values in the combo, surround
'combo value with '' or "" (gender). If numerica value (due to
'lookup tables) don't surround (Occupation)
Dim strFilter As String
If Not IsNull(Me.ComboGender) Then
'assumes fld nm is gender and stuffing an M or F
strFilter = strFilter & _
"Gender = '" & Me.ComboGender & "' And "
Endif
If Not IsNull(Me.ComboOccupation) Then
'assumes fld nm is gender and stuffing an M or F
strFilter = strFilter & _
"Occupation = " & ComboOccupation & " And "
Endif
...continue this method for rest of combos
'now remove word AND at end of strFilter
if strFilter "" Then 'not all combos were null
strFilter = Left(strFilter,len(strFilter)-5)
Endif
'now set filter
Me.Filter = strFilter 'strFilter looks like Where statement
'without the word "Where"
'now turn on filter
Me.FilterOn = True
MakeFilter = True
End Function
This creates the filter and is called anytime you change a value in the
combos or resetting the filter.