I have a report that filters the information within it by means of a ‘pop-up’ form filter.
It currently contains two combo boxes as [Filter1] (Postcode) and [Filter2] (Suburb).
It works great when just processing one field at a time eg. Postcode or Suburb, where only one value is filtered for. Both these fields are ‘text’ Data Types.
The ‘Set Filter’ button runs the following code:-
Private Sub b_Set_Click()
Dim strSQL As String, intCounter As Integer
'Build SQL String
For intCounter = 1 To 2
If Me("Filter" & intCounter) <> "" Then
strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " = " & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And "
End If
Next
If strSQL <> "" Then
'Strip Last " And "
strSQL = Left(strSQL, (Len(strSQL) - 4))
'Set the Filter property
Reports![Contacts].Filter = strSQL
Reports![Contacts].FilterOn = True
End If
End Sub
I want to add/include two more Filter combo boxes – [Filter3] (from Postcode) and [Filter4] (to Postcode) - to allow for searching between Postcode values eg. Postcode >= [Filter3] (say 4000) AND <=[Filter4] (say 4300).
In a query I would use in the Postcode field : >=[Filter3] And <=[Filter4] and it would then provide pop-ups asking for Parameter values for [Filter3] And [Filter4].
In the pop-up filter form for the report I have the After Update for [Filter3] set as:
Private Sub Filter3_AfterUpdate()
Me.Filter4.Requery
End Sub
which resets the values in combo box [Filter4] at values greater than the [Filter3] value selected.
The user can then select a value in combo box [Filter4] which is greater than the value selected in combo box [Filter3].
The user would select either [Filter1]:Postcode OR [Filter2]:Suburb OR [Filter3]:from Postcode AND [Filter4]:to Postcode.
I now am having problems getting the code right so that I can use the four [Filters] on the form and have the report filtered according to the para above.
What would I need to include in the Private Sub b_Set_Click() code to allow thing to work as I would like.
Any assistance appreciated.
mortonsafari