theinviter
Registered User.
- Local time
- Yesterday, 19:35
- Joined
- Aug 14, 2014
- Messages
- 244
Dears;
I need your support, as I have a form with multiple un-bound combo-box and need to filter the form based on the user selection. as i tried below but not work Properly.
and will not filer the form.
so can you guide me how to solve this, File attached.
Private Sub filterThisForm2()
On Error GoTo errhandler:
n = 1 / 0 ' cause an error
Dim strFilter As String
If Len(Me!Combo_Clinic & "") <> 0 Then
strFilter = "[Location Code] Like """ & Me!Combo_Clinic & """ And "
End If
If Len(Me!Combo_Machine & "") <> 0 Then
strFilter = strFilter & "[Machine Name] Like ""*" & Me!Combo_Machine & "*"" And "
End If
If Len(Me!Combo_Brand & "") <> 0 Then
strFilter = "[Brand] Like ""*" & Me!Combo_Brand & "*"" And "
End If
If Len(Me!Combo_Status & "") <> 0 Then
strFilter = "[Repair Status] Like """ & Me!Combo_Status & """ And "
End If
If Len(Me!Date_From & "") <> 0 Then
strFilter = "[Date of Occurrence] >= #" & Format(Nz(Me.Date_From, 1), "yyyy\/mm\/dd") & "# AND [Date of Occurrence] <= #" & Format(Nz(Me.Date_To, 2958465), "yyyy\/mm\/dd") & "# And "
End If
If Len(strFilter) <> 5 Then
strFilter = Left$(strFilter, Len(strFilter) - 5)
With Me
.Filter = strFilter
.FilterOn = True
End With
Else
Me.FilterOn = False
End If
Exit Sub
errhandler:
' error handling code
Resume Next
End Sub
I need your support, as I have a form with multiple un-bound combo-box and need to filter the form based on the user selection. as i tried below but not work Properly.
and will not filer the form.
so can you guide me how to solve this, File attached.
Private Sub filterThisForm2()
On Error GoTo errhandler:
n = 1 / 0 ' cause an error
Dim strFilter As String
If Len(Me!Combo_Clinic & "") <> 0 Then
strFilter = "[Location Code] Like """ & Me!Combo_Clinic & """ And "
End If
If Len(Me!Combo_Machine & "") <> 0 Then
strFilter = strFilter & "[Machine Name] Like ""*" & Me!Combo_Machine & "*"" And "
End If
If Len(Me!Combo_Brand & "") <> 0 Then
strFilter = "[Brand] Like ""*" & Me!Combo_Brand & "*"" And "
End If
If Len(Me!Combo_Status & "") <> 0 Then
strFilter = "[Repair Status] Like """ & Me!Combo_Status & """ And "
End If
If Len(Me!Date_From & "") <> 0 Then
strFilter = "[Date of Occurrence] >= #" & Format(Nz(Me.Date_From, 1), "yyyy\/mm\/dd") & "# AND [Date of Occurrence] <= #" & Format(Nz(Me.Date_To, 2958465), "yyyy\/mm\/dd") & "# And "
End If
If Len(strFilter) <> 5 Then
strFilter = Left$(strFilter, Len(strFilter) - 5)
With Me
.Filter = strFilter
.FilterOn = True
End With
Else
Me.FilterOn = False
End If
Exit Sub
errhandler:
' error handling code
Resume Next
End Sub