R
RobDavo
Hi,
I need some help. I have a form based on a query which lists wine in a
cellar. I want to allow the users to filter the content on the form by using
multiple filters. The following code works well.
Private Sub CmdApplyFilter_Click()
Dim strWhere As String
strWhere = ""
Dim strNonZero As String
Dim strType As String
Dim strYear As String
strNonZero = ""
strType = ""
strYear = ""
' from a check box to show either only current wine in cellar or all wine
included that which has been drunk - no bottles in cellar
If CheckNonZero = True Then
strNonZero = "Bottle_remaining > 0"
Else
strNonZero = "Bottle_remaining >= 0"
End If
' select "red", "white", etc
If Not IsNull([ComboSelectType]) Then
strType = " And Type= '" & ComboSelectType & "'"
End If
' select year of the wine
If Not IsNull([ComboYear]) Then
strYear = " And Year= '" & ComboYear & "'"
End If
strWhere = strNonZero & strType & strYear
DoCmd.ApplyFilter , strWhere
FilterOn = True
End Sub
The problem occurs when the user clears the filter, re-selects parameters
and re-filters the form.
The form's property "Filter" retains values not selected, eg when the user
selects all 3 values and then re-filter only 2 of these and the filter
property keeps all 3 eg "Bottle_remaining > 0 And Type= 'Red' And Year= '' "
which is then not a valid Where statement and no records are shown.
This problem is cleared by closing and re-opening the form.
Any suggestions would be appreciated.
Thanks
Rob
I need some help. I have a form based on a query which lists wine in a
cellar. I want to allow the users to filter the content on the form by using
multiple filters. The following code works well.
Private Sub CmdApplyFilter_Click()
Dim strWhere As String
strWhere = ""
Dim strNonZero As String
Dim strType As String
Dim strYear As String
strNonZero = ""
strType = ""
strYear = ""
' from a check box to show either only current wine in cellar or all wine
included that which has been drunk - no bottles in cellar
If CheckNonZero = True Then
strNonZero = "Bottle_remaining > 0"
Else
strNonZero = "Bottle_remaining >= 0"
End If
' select "red", "white", etc
If Not IsNull([ComboSelectType]) Then
strType = " And Type= '" & ComboSelectType & "'"
End If
' select year of the wine
If Not IsNull([ComboYear]) Then
strYear = " And Year= '" & ComboYear & "'"
End If
strWhere = strNonZero & strType & strYear
DoCmd.ApplyFilter , strWhere
FilterOn = True
End Sub
The problem occurs when the user clears the filter, re-selects parameters
and re-filters the form.
The form's property "Filter" retains values not selected, eg when the user
selects all 3 values and then re-filter only 2 of these and the filter
property keeps all 3 eg "Bottle_remaining > 0 And Type= 'Red' And Year= '' "
which is then not a valid Where statement and no records are shown.
This problem is cleared by closing and re-opening the form.
Any suggestions would be appreciated.
Thanks
Rob