I have been working away on a form designed to serve up many combinations of data depending on what the form controls are set to. I have three combo boxes, each of which limits records when populated and returns all when NULL.
I have three radio buttons which set the values for three text boxes depending on whether they are checked or not, and I have folded code into my filter to return all values if they are not checked.
But unlike the other filters where I want each to successively limit the records, I want my radio buttons, denoted in BOLD by the text boxes in the code below to return all that are True or not NULL, yet return all if none are checked.
Right now everything works great if I check one, but when I check a second all records are filtered out and none are returned.
This is my code:
Private Sub RunFilter3()
Dim strFilter As String
Dim bFilter As Boolean
bFilter = False
strFilter = ""
If Nz(Me.ComboRunYear, 0) > 0 Then 'Period
If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
strFilter = strFilter & "RunYear = " & Me.ComboRunYear
bFilter = True
End If
If Nz(Me.ComboWater, 0) > 0 Then 'TargetType
If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
strFilter = strFilter & "StreamName = '" & Me.ComboWater & "'"
bFilter = True
End If
If Nz(Me.ComboAgency, 0) > 0 Then 'TargetType
If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
strFilter = strFilter & "AgencyName = '" & Me.ComboAgency & "'"
bFilter = True
End If
If Nz(Me.STHDValue, 0) > 0 Then 'TargetType
If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
strFilter = strFilter & "Species_AbbrDesc = '" & Me.STHDValue & "'"
bFilter = True
End If
If Nz(Me.CUTTValue, 0) > 0 Then 'TargetType
If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
strFilter = strFilter & "Species_AbbrDesc = '" & Me.CUTTValue & "'"
bFilter = True
End If
If Nz(Me.COHOValue, 0) > 0 Then 'TargetType
If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
strFilter = strFilter & "Species_AbbrDesc = '" & Me.COHOValue & "'"
bFilter = True
End If
If bFilter Then
Me.STHD_Project_Data_Export_SF.Form.OrderBy = ""
Me.STHD_Project_Data_Export_SF.Form.Filter = strFilter
Me.STHD_Project_Data_Export_SF.Form.FilterOn = True
Else
Me.STHD_Project_Data_Export_SF.Form.FilterOn = False
End If
End Sub
Thank you for taking the time to check this out.
I have three radio buttons which set the values for three text boxes depending on whether they are checked or not, and I have folded code into my filter to return all values if they are not checked.
But unlike the other filters where I want each to successively limit the records, I want my radio buttons, denoted in BOLD by the text boxes in the code below to return all that are True or not NULL, yet return all if none are checked.
Right now everything works great if I check one, but when I check a second all records are filtered out and none are returned.
This is my code:
Private Sub RunFilter3()
Dim strFilter As String
Dim bFilter As Boolean
bFilter = False
strFilter = ""
If Nz(Me.ComboRunYear, 0) > 0 Then 'Period
If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
strFilter = strFilter & "RunYear = " & Me.ComboRunYear
bFilter = True
End If
If Nz(Me.ComboWater, 0) > 0 Then 'TargetType
If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
strFilter = strFilter & "StreamName = '" & Me.ComboWater & "'"
bFilter = True
End If
If Nz(Me.ComboAgency, 0) > 0 Then 'TargetType
If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
strFilter = strFilter & "AgencyName = '" & Me.ComboAgency & "'"
bFilter = True
End If
If Nz(Me.STHDValue, 0) > 0 Then 'TargetType
If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
strFilter = strFilter & "Species_AbbrDesc = '" & Me.STHDValue & "'"
bFilter = True
End If
If Nz(Me.CUTTValue, 0) > 0 Then 'TargetType
If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
strFilter = strFilter & "Species_AbbrDesc = '" & Me.CUTTValue & "'"
bFilter = True
End If
If Nz(Me.COHOValue, 0) > 0 Then 'TargetType
If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
strFilter = strFilter & "Species_AbbrDesc = '" & Me.COHOValue & "'"
bFilter = True
End If
If bFilter Then
Me.STHD_Project_Data_Export_SF.Form.OrderBy = ""
Me.STHD_Project_Data_Export_SF.Form.Filter = strFilter
Me.STHD_Project_Data_Export_SF.Form.FilterOn = True
Else
Me.STHD_Project_Data_Export_SF.Form.FilterOn = False
End If
End Sub
Thank you for taking the time to check this out.