Hey Guys I need help constructing the VBA code for this form so that a user can be able to select the multiple criteria and click search and the table below will filter the criteria selected. I included the screen shot and all fields names are the same names as the labels. Here's my current code:
Private Sub Search_Click()
Dim strWhere As String
Dim lngLen As Long
Const conJetDate = "\#mm\/dd\/yyyy\#"
If Not IsNull(Me.AssignedTo) Then
strWhere = strWhere & "([AssignedTo] Like '*" & Me.AssignedTo & "*') AND"
End If
If Not IsNull(Me.OpenedBy) Then
strWhere = strWhere & "([OpenedBy] Like '*" & Me.OpenedBy & "*') AND"
End If
If Not IsNull(Me.Status) Then
strWhere = strWhere & "([Status] Like '*" & Me.Status & "*')AND"
End If
If Not IsNull(Me.Category) Then
strWhere = strWhere & "([Category] Like '*" & Me.Category & "*')AND"
End If
If Not IsNull(Me.Priority) Then
strWhere = strWhere & "([Priority] Like '*" & Me.Priority & "*')AND"
End If
If Not IsNull(Me.OpenedDateFrom) Then
strWhere = strWhere & "([EnteredOn] >= " & Format(Me.OpenedDateFrom, conJetDate) & ") AND "
End If
If Not IsNull(Me.DueDateFrom) Then
strWhere = strWhere & "([EnteredOn] <= " & Format(Me.DueDateFrom, conJetDate) & ") AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "No criteria", vbInformation, "Nothing to do."
Else
End If
strWhere = Left$(strWhere, lngLen)
Me.Filter = strWhere
Me.FilterOn = True
End Sub
Any help will be greatly appreciated
Private Sub Search_Click()
Dim strWhere As String
Dim lngLen As Long
Const conJetDate = "\#mm\/dd\/yyyy\#"
If Not IsNull(Me.AssignedTo) Then
strWhere = strWhere & "([AssignedTo] Like '*" & Me.AssignedTo & "*') AND"
End If
If Not IsNull(Me.OpenedBy) Then
strWhere = strWhere & "([OpenedBy] Like '*" & Me.OpenedBy & "*') AND"
End If
If Not IsNull(Me.Status) Then
strWhere = strWhere & "([Status] Like '*" & Me.Status & "*')AND"
End If
If Not IsNull(Me.Category) Then
strWhere = strWhere & "([Category] Like '*" & Me.Category & "*')AND"
End If
If Not IsNull(Me.Priority) Then
strWhere = strWhere & "([Priority] Like '*" & Me.Priority & "*')AND"
End If
If Not IsNull(Me.OpenedDateFrom) Then
strWhere = strWhere & "([EnteredOn] >= " & Format(Me.OpenedDateFrom, conJetDate) & ") AND "
End If
If Not IsNull(Me.DueDateFrom) Then
strWhere = strWhere & "([EnteredOn] <= " & Format(Me.DueDateFrom, conJetDate) & ") AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "No criteria", vbInformation, "Nothing to do."
Else
End If
strWhere = Left$(strWhere, lngLen)
Me.Filter = strWhere
Me.FilterOn = True
End Sub
Any help will be greatly appreciated