I modded the code to remove products from the lstsrl list, but not cities from the lstsl list:
Dim varItem As Variant
Dim strwhere As String
Dim strreport As String
Dim rs As ADODB.Recordset
Dim sSQL As String
Dim lRecord As Long
Dim sRecord As String
Dim ctrl As Control
Dim intCurrentRow As Integer
strwhere = ""
strreport = "Product1"
'Using Text as Column(0)
If lstsl.ItemsSelected.Count > 0 Then
strwhere = strwhere & "("
For Each varItem In lstsl.ItemsSelected
strwhere = strwhere & "[city] = '" _
& Me![lstsl].Column(0, varItem) & "' Or "
Next varItem
strwhere = Left(strwhere, Len(strwhere) - 4)
strwhere = strwhere & ")"
End If
If Len(strwhere) > 0 Then strwhere = strwhere & " And "
'Using integer PK as Column(0)
If lstsrl.ItemsSelected.Count > 0 Then
strwhere = strwhere & "("
For Each varItem In lstsrl.ItemsSelected
strwhere = strwhere & "[Serial No] =" & Me![lstsrl].Column(0, varItem) & " Or "
Next varItem
strwhere = Left(strwhere, Len(strwhere) - 4)
strwhere = strwhere & ")"
End If
If Len(strwhere) > 0 Then strwhere = strwhere
'For Text
Set ctrl = Me.lstsrl
For intCurrentRow = 0 To ctrl.ListCount - 1
If ctrl.Selected(intCurrentRow) Then
lRecord = ctrl.Column(0, intCurrentRow)
sSQL = "UPDATE Product SET [Print] = Yes WHERE [Serial No] = " & lRecord
Set rs = New ADODB.Recordset
rs.Open sSQL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
End If
Next intCurrentRow
intCurrentRow = 0
Me.lstsrl.Requery
The resulting WHERE clause produced when I selected the City I created called "Columbia" and the third product in the list (Serial No 2) was:
strwhere = ([city] = 'Columbia') AND ([Serial No] = 2)
This could be expressed without all the () like:
[city] = 'Columbia' AND [Serial No] = 2
Anyway, this worked for me and removed the products from the list. Not the cities. Did you also want cities removed?
mmcdonal
Look it up at:
http://wrox.books24x7.com