Filter as you type in multiple fields

31 Views Asked by At

He there, In access form, I have below code, to filter while typing. Its working well, but if any filed is empty or null, not showing results. example: FirstName is not null, LastName is null, there is no results.

Can somebady help me to solve this? I am new in VBA, be specific in giving sugestion.

Code:

Private Sub FilterFirstName_Change()
    Dim FName
    FName = FilterFirstName.Text
    
    If Trim(FName & "") = vbNullString And IsNull(FilterLastName) And IsNull(FilterPhones) Then
        Me.Filter = ""
        Me.FilterOn = False
        Me.FilterFirstName.SetFocus
      
    Else
       Me.Filter = "FirstName Like '*" & FilterFirstName.Text & "*'" & _
                   " And LastName Like '*" & FilterLastName & "*'" & _
                   " And Phones Like '*" & FilterPhones & "*'"

        Me.FilterOn = True
        Me.FilterFirstName.SelStart = FilterFirstName.SelLength
    End If
    
End Sub
0

There are 0 best solutions below