Hi All,
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On the microsoft forum I found multiple examples of code from HansV and simliar code from NeoPa here that I am trying to understand and adapt.
The code below is works great for me so long as both independant combo boxes have selections, but despite everything I've read, it doesn't seem to leave all the values for the field when the one or either of the combo boxes is left blank.
Where I am having trouble is with the AND logic of the script, when a combo box is left blank (i.e they might just want to filter by Vendor or Part Type only). I have run the individual codes directly from the combo boxes using AFTER UPDATE, but am having the same trouble when I call the procedure.
As always, any help is greatly appreciated.
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On the microsoft forum I found multiple examples of code from HansV and simliar code from NeoPa here that I am trying to understand and adapt.
The code below is works great for me so long as both independant combo boxes have selections, but despite everything I've read, it doesn't seem to leave all the values for the field when the one or either of the combo boxes is left blank.
Code:
Private Sub FilterMe()
Dim strWhere As String
If Not IsNull(Me.cmbVendorSelect) Then
strWhere = strWhere & " AND [PartVendor]='" & Me.cmbVendorSelect & "'"
'how is this handled if the cbo is left blank? trying to learn...
End If
If Not IsNull(Me.cmbTypeSelect) Then
strWhere = strWhere & " AND [PartType]='" & Me.cmbTypeSelect & "'"
End If
If strWhere = "" Then
Me.Filter = ""
Me.FilterOn = False
'code seems to fail here when both comboboxes are blank, or am I misunderstanding the code?
Else
Me.Filter = Mid(strWhere, 6)
Me.FilterOn = True
End If
End Sub
As always, any help is greatly appreciated.
Comment