Okay, I cleaned this up a bit:
Private Sub filter_Click()
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 & "master.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 lstprdt.ItemsSelected.Count > 0 Then
strwhere = strwhere & "("
For Each varItem In lstprdt.ItemsSelected
strwhere = strwhere & "Master.Product =" & Me![lstprdt].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.lstsl
For intCurrentRow = 0 To ctrl.ListCount - 1
If ctrl.Selected(intCurrentRow) Then
sRecord = ctrl.Column(0, intCurrentRow)
sSQL = "UPDATE Product SET [Print] = Yes WHERE [city] = " & sRecord
Set rs = New ADODB.Recordset
rs.Open sSQL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
End If
Next intCurrentRow
intCurrentRow = 0
'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
Me.lstsl.Requery
Me.lstsrl.Requery
DoCmd.OpenReport strreport, acViewReport, , strwhere
End Sub
Is that working?
mmcdonal
Look it up at:
http://wrox.books24x7.com