I am using the following code in a list box, its working fine.
With this list box I select the customers whose report I want to view.
How can I change this code that by cliking on the button it selects all the customers.
See the Code I am using.
Private Sub cmdOpenReportMultiple_Click()
On Error GoTo Err_Handler
Const REPORTNAME = "General Purchase"
Const MESSAGETEXT = "No Account Title's Selected"
Dim varItem As Variant
Dim strCustomerIDList As String
Dim strCriteria As String
Dim ctrl As Control
Set ctrl = Me.lstCustomers
If ctrl.ItemsSelected.Count > 0 Then
For Each varItem In ctrl.ItemsSelected
strCustomerIDList = strCustomerIDList & "," & ctrl.ItemData(varItem)
Next varItem
' remove leading comma
strCustomerIDList = Mid(strCustomerIDList, 2)
strCriteria = "CoId In(" & strCustomerIDList & ")"
DoCmd.OpenReport REPORTNAME, _
View:=acViewPreview, _
WhereCondition:=strCriteria
Else
MsgBox MESSAGETEXT, vbExclamation, "Invalid operation"
End If
Exit_Here:
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error"
Resume Exit_Here
End Sub