Private Sub cmdReport_Click()
On Error GoTo Err_Handler
'Dim db As DAO.Database
'Dim qdf As DAO.QueryDef
Dim ctl As Control
Dim varItem As Variant
Dim strParam As String, strRptQuery As String
'First validate we have all the data we need
If IsNull(Me.cboEmployeeID) Then
MsgBox ("Employee is mandatory")
Me.cboEmployeeID.SetFocus
Exit Sub
End If
If IsNull(Me.txtStartdate) Then
MsgBox ("Start date is mandatory")
Exit Sub
End If
If IsNull(Me.txtEnddate) Then
MsgBox ("End date is mandatory")
Exit Sub
End If
strRptQuery = "qryEmployeeHours"
Set ctl = Me!lstDayType
'Open the report with an OpenArgs value to get selected hours for employee
' Now select what type of day records from listbox
If ctl.ItemsSelected.Count > 0 Then
For Each varItem In ctl.ItemsSelected
strParam = strParam & ctl.ItemData(varItem) & ","
Next varItem
Else
MsgBox ("At least one Day Type is required")
Exit Sub
End If
' Need to pass the criteria as a string
strParam = " IN (" & Left(strParam, Len(strParam) - 1) & ")"
'Debug.Print strParam
'Set db = CurrentDb
'Set qdf = db.QueryDefs(strRptQuery)
'qdf.Parameters("pInList") = strParam
'qdf.Close
strParam = "[DateType]" & strParam
DoCmd.OpenReport "rptHours", acViewReport, , strParam, , "Selected"
'docmd.OpenReport "tt",acViewPreview,,"[DateType]=15",,,
Exit_Sub:
Set ctl = Nothing
'Set db = Nothing
'Set qdf = Nothing
Err_Exit:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & " " & Err.Description
Resume Exit_Sub
End Sub