I'm going to start off by saying I have no clue what any of the code I post means (I'm a complete newb when it comes to VBA). I'm learning using the "trial by fire" method. I found the code I'm using in this forum and it does part of what I need it to do.
Here's the problem. I have a main form with multiple combo boxes that filter a subform datasheet. In my main form combo box [PR_Filter] I added a selection titled "<Blanks>". When I select "<Blanks>", I want it to filter my subform field [PR] for NULL values. If I select anything else I want it to filter on that selection. I cannot get the NULL filter to work. Any help is greatly appreciated!
Here is the code that I have (Red is the field I need the NULL values):
Here's the problem. I have a main form with multiple combo boxes that filter a subform datasheet. In my main form combo box [PR_Filter] I added a selection titled "<Blanks>". When I select "<Blanks>", I want it to filter my subform field [PR] for NULL values. If I select anything else I want it to filter on that selection. I cannot get the NULL filter to work. Any help is greatly appreciated!
Here is the code that I have (Red is the field I need the NULL values):
Code:
Private Function PurchaseFilter()
Dim strFilter As String
Dim bFilter As Boolean
bFilter = False
strFilter = ""
If Nz(Me.ID_Filter, "") > "" Then 'ID
If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
strFilter = strFilter & "ID = '" & Me.ID_Filter & "'"
bFilter = True
End If
If Nz(Me.Item_Filter, "") > "" Then 'Item
If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
strFilter = strFilter & "Item = '" & Me.Item_Filter & "'"
bFilter = True
End If
If Nz(Me.WO_Filter, "") > "" Then 'WorkOrder
If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
strFilter = strFilter & "WorkOrder = " & Me.WO_Filter & ""
bFilter = True
End If
If Nz(Me.PO_Filter, "") > "" Then 'Puchase Order
If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
strFilter = strFilter & "PO = " & Me.PO_Filter & ""
bFilter = True
End If
[COLOR=red]If Nz(Me.PR_Filter, "") > "" Then 'Puchase Request[/COLOR]
[COLOR=red]If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "[/COLOR]
[COLOR=red]strFilter = strFilter & "PR = " & Me.PR_Filter & ""[/COLOR]
[COLOR=red]bFilter = True[/COLOR]
[COLOR=red]End If[/COLOR]
If bFilter Then
Me.PU_Purchasing_Update_sub.Form.OrderBy = ""
Me.PU_Purchasing_Update_sub.Form.Filter = strFilter
Me.PU_Purchasing_Update_sub.Form.FilterOn = True
Else
Me.PU_Purchasing_Update_sub.Form.FilterOn = False
End If
End Function
Last edited: