Pharma Down
Registered User.
- Local time
- Today, 12:29
- Joined
- Dec 1, 2011
- Messages
- 67
Having just tried this I know that it doesn't work...
Dim strWhere As String
Dim ctl As Control
Dim varItem As Variant
'make sure a selection has been made
If Me.lstEmployees.ItemsSelected.Count = 0 Then
MsgBox "Must select at least 1 employee"
Exit Sub
End If
If Not IsDate(Me.txtFromDate) Then
MsgBox "Please enter a start date for the report period"
Exit Sub
End If
If Not IsDate(Me.txtToDate) Then
MsgBox "Please enter an end date for the report period"
Exit Sub
End If
'add selected values to string
Set ctl = Me.lstEmployees
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
'trim trailing comma
strWhere = Left(strWhere, Len(strWhere) - 1)
'open the report, restricted to the selected items
DoCmd.OpenReport "rptEmployees", acPreview, , "EmpID IN(" & strWhere & ") AND DateOfBirth >= #" & Forms!frmOpenReport.txtFromDate & "# AND DateOfBirth <=#" & Forms!frmOpenReport.txtToDate & "#"