C
Confused
I added a MultiSelect List Box and now I am trying to make it work with the
other combo boxes on the form to filter records.
It apparently doesn't work the same way as filtering with the combos. I
have attached the code (adapted from AllenBrowne.com). What I added is the
part "Me.LstCategory". Could someone provide some insight into how to
adapt this to make it work to filter records in the LstCategory List Box
along with the other Combo boxes?
Private Sub cmdfilter_Click()
Dim strWhere As String
Dim lngLen As Long
Const conJetDate = "\#mm\/dd\/yyyy\#"
If Not IsNull(Me.cboEmployees) Then
strWhere = strWhere & _
" [CLECID] IN(SELECT [cLECID]" & _
" FROM tblemployeeAssignments" & _
" WHERE [employeeId] = " & Me.cboEmployees & ") AND "
End If
If Not IsNull(Me.Text58) Then
strWhere = strWhere & "([CLEC Name] Like ""*" & Me.Text58 & "*"") And "
End If
If Not IsNull(Me.LstCategory) Then
strWhere = strWhere & _
" [CLECID] In (Select [CLECID]" & _
" From [CLEC Systems3]" & _
"Where [system id] = " & Me.LstCategory & ") And "
End If
'See if the string has more than 5 characters (a trailng " AND ") to remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the "
AND " at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to
Immediate Window (Ctrl+G).
'Debug.Print strWhere
'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub
other combo boxes on the form to filter records.
It apparently doesn't work the same way as filtering with the combos. I
have attached the code (adapted from AllenBrowne.com). What I added is the
part "Me.LstCategory". Could someone provide some insight into how to
adapt this to make it work to filter records in the LstCategory List Box
along with the other Combo boxes?
Private Sub cmdfilter_Click()
Dim strWhere As String
Dim lngLen As Long
Const conJetDate = "\#mm\/dd\/yyyy\#"
If Not IsNull(Me.cboEmployees) Then
strWhere = strWhere & _
" [CLECID] IN(SELECT [cLECID]" & _
" FROM tblemployeeAssignments" & _
" WHERE [employeeId] = " & Me.cboEmployees & ") AND "
End If
If Not IsNull(Me.Text58) Then
strWhere = strWhere & "([CLEC Name] Like ""*" & Me.Text58 & "*"") And "
End If
If Not IsNull(Me.LstCategory) Then
strWhere = strWhere & _
" [CLECID] In (Select [CLECID]" & _
" From [CLEC Systems3]" & _
"Where [system id] = " & Me.LstCategory & ") And "
End If
'See if the string has more than 5 characters (a trailng " AND ") to remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the "
AND " at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to
Immediate Window (Ctrl+G).
'Debug.Print strWhere
'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub