We keep track of a worker's hour and whether those hours are "overtime" or "regular time" with an "earn_code" value. I had a query with input parameters built in, but that didn't give supervisors enough prompting. Thus the use of an input parameter form.
On the form, a supervisor can enter a userID, a date range and an option to see regular time, overtime or both. These input parameters feed a query that feeds a report.
Below is my code that builds the SQL for DoCmd.OpenReport method.
It only works when case2 (Overtime), and doesn't when case1 (Regular time) or case3 (both OT & Reg). When I copy/paste the sqlReport into the original query, it works fine for all cases.
I'm missing something, but have been looking at it so long, I can't see my problem.
Any help is greatly appreciated.
* t_dmz_people.mpac = 23331 and t_dmz_equipment.start_date between #1/1/2011# and #5/1/2011# and t_dmz_equipment.earn_code = 0
On the form, a supervisor can enter a userID, a date range and an option to see regular time, overtime or both. These input parameters feed a query that feeds a report.
Below is my code that builds the SQL for DoCmd.OpenReport method.
It only works when case2 (Overtime), and doesn't when case1 (Regular time) or case3 (both OT & Reg). When I copy/paste the sqlReport into the original query, it works fine for all cases.
I'm missing something, but have been looking at it so long, I can't see my problem.
Any help is greatly appreciated.
Code:
' set up parameter pass variables
Dim sqlBegDate As Date
Dim sqlEndDate As Date
Dim sqlEmp As Double
Dim sqlReport As String
Dim stDocName As String
Dim sqlReg As Double
Dim sqlOT As Double
' pass input parameters
sqlBegDate = Me.begDate
sqlEndDate = Me.endDate
sqlEmp = Me.dEmp
stDocName = "rDataEntryReport"
sqlReg = "0"
sqlOT = "1"
Select Case Options
Case 1 ' regular time
sqlEarnCode = " and t_dmz_equipment.earn_code = " & [sqlReg] & ""
Case 2 ' overtime
sqlEarnCode = " and t_dmz_equipment.earn_code = " & [sqlOT] & ""
Case 3 ' regular and overtime
sqlEarnCode = " and t_dmz_equipment.earn_code = " & [sqlReg] & " or t_dmz_equipment.earn_code = " & [sqlOT] & ""
End Select
' build sql for query
sqlReport = " t_dmz_people.mpac = " & [sqlEmp] & "" ' AND ((T_DMZ_EQUIPMENT.START_DATE) Between #" & [sqlBegDate] & "# And #" & [sqlEndDate] & "# AND ((T_DMZ_EQUIPMENT.EARN_CODE)=0)"
sqlReport = sqlReport & " and t_dmz_equipment.start_date between #" & [sqlBegDate] & "# and #" & [sqlEndDate] & "#"
sqlReport = sqlReport & sqlEarnCode
Debug.Print sqlReport*
DoCmd.OpenReport stDocName, acViewPreview, qDataEntryReport, sqlReport, acWindowNormal
DoCmd.CLOSE acForm, "f_reportform"
End Sub