D
DOYLE60
The code copied below is for a list box that must have at least one item
chosen. The items chosen are written to a query.
However, I need to change this code so that if nothing is chosen, than all are
actually chosen and written to the query. But if one is chosen, then that one
is chosen (not the others not chosen). In other words, I want it to work like
my Combo Boxes where if left null, all are chosen (for a filtering query), and
if filled in, just that one is chosen.
Thanks,
Matt
_____________________________________
Private Sub Command9_DblClick(Cancel As Integer)
Dim Q As QueryDef, db As Database
Dim Criteria As String
Dim ctl As Control
Dim Itm As Variant
' Build a list of the selections.
Set ctl = Me![SalesRepsChosen]
For Each Itm In ctl.ItemsSelected
If Len(Criteria) = 0 Then
Criteria = Chr(34) & ctl.ItemData(Itm) & Chr(34)
Else
Criteria = Criteria & "," & Chr(34) & ctl.ItemData(Itm) _
& Chr(34)
End If
Next Itm
If Len(Criteria) = 0 Then
Itm = MsgBox("You must select one or more items in the list box!", 0, "No
Selection Made")
Exit Sub
End If
' Modify the query.
Set db = CurrentDb()
Set Q = db.QueryDefs("SandraSalesRepqry")
Q.SQL = "Select * From [SalesReptbl] Where [SalesRepLastName] In(" & Criteria
& ");"
Q.Close
End Sub
chosen. The items chosen are written to a query.
However, I need to change this code so that if nothing is chosen, than all are
actually chosen and written to the query. But if one is chosen, then that one
is chosen (not the others not chosen). In other words, I want it to work like
my Combo Boxes where if left null, all are chosen (for a filtering query), and
if filled in, just that one is chosen.
Thanks,
Matt
_____________________________________
Private Sub Command9_DblClick(Cancel As Integer)
Dim Q As QueryDef, db As Database
Dim Criteria As String
Dim ctl As Control
Dim Itm As Variant
' Build a list of the selections.
Set ctl = Me![SalesRepsChosen]
For Each Itm In ctl.ItemsSelected
If Len(Criteria) = 0 Then
Criteria = Chr(34) & ctl.ItemData(Itm) & Chr(34)
Else
Criteria = Criteria & "," & Chr(34) & ctl.ItemData(Itm) _
& Chr(34)
End If
Next Itm
If Len(Criteria) = 0 Then
Itm = MsgBox("You must select one or more items in the list box!", 0, "No
Selection Made")
Exit Sub
End If
' Modify the query.
Set db = CurrentDb()
Set Q = db.QueryDefs("SandraSalesRepqry")
Q.SQL = "Select * From [SalesReptbl] Where [SalesRepLastName] In(" & Criteria
& ");"
Q.Close
End Sub