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.
Expand|Select|Wrap|Line Numbers
- 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.