I don't think it's anything specific in the code, Dirk. The problem seems to be a fundamental one when a multi-select list box's MultiSelect property is set to 'Extended' rather than "Simple'. I can observe it in my Multiselect demo if I change the property
to 'Extended' from its usual setting of 'Simple'. It can rightly be called a bug, I think. The code behind one of the forms in my demo is:
Private Sub cmdOpenReport_Click()
Dim varItem As Variant
Dim strEmployeeIDList As String
Dim strCriteria As String
Dim ctrl As Control
Set ctrl = Me.lstEmployees
If ctrl.ItemsSelected.Count > 0 Then
For Each varItem In ctrl.ItemsSelected
strEmployeeIDList = strEmployeeIDList & "," & ctrl.ItemData(varItem)
Next varItem
' remove leading comma
strEmployeeIDList = Mid(strEmployeeIDList, 2)
strCriteria = "EmployeeID In(" & strEmployeeIDList & ")"
DoCmd.OpenReport "rptEmployees", _
View:=acViewPreview, _
WhereCondition:=strCriteria
Else
MsgBox "No employees selected", vbInformation, "Warning"
End If
End Sub
If rows are selected en bloc and then selectively deselected with Ctrl-Click, after the above code has executed, only the topmost contiguous block of items in the list box remains selected. As the OP says this could be confusing, but also it prevents the same
set of selected rows being used again without reselecting the missing items. My demo outputs the report in print preview, but if I had a second button to send the report to a printer for instance, the user would have to go to the trouble of making the further
selections.
The easy solution is to set the MultiSelect property to 'Simple', but with a long list this could make multiple selections tedious. A possible solution with a seeing of 'Extended' might be to write each selected value to an array in the loop. Then, after
exiting the loop, reselect the items by stepping through the value in the array, setting the Selected property of the row to True for each. I haven't tried it, though.