Hello All,
I am trying to open a report filtered by a date range (that part works fine) and also based on a value from a listbox when the user selects another criteria for the filtered report. That is where the problem is occurring.
I have a report named rpt_DutyTime (under properties filter is on) and the control source is qry_DutyTime.
When I open my form and select my dates and the particular base and click the button to view it I get another form asking for the tblBases. So I put it in manually and it opens the report but with ALL bases not the one that I typed in or selected.
Here is my code if someone could take a look and tell me where I'm going wrong:
I am trying to open a report filtered by a date range (that part works fine) and also based on a value from a listbox when the user selects another criteria for the filtered report. That is where the problem is occurring.
I have a report named rpt_DutyTime (under properties filter is on) and the control source is qry_DutyTime.
When I open my form and select my dates and the particular base and click the button to view it I get another form asking for the tblBases. So I put it in manually and it opens the report but with ALL bases not the one that I typed in or selected.
Here is my code if someone could take a look and tell me where I'm going wrong:
Code:
Private Sub Command8_Click()
mybase = Me.lstBases
If Me.ckAll = True Then
'Routine opens report with ALL the bases in the listbox and the selected date range
On Error GoTo Err_runQuery_Click
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "rpt_DutyTime", acViewPreview, , "[tblDate] between #" & Me.txtStartDate & "# and # " & Me.txtEndDate & "#"
DoCmd.Maximize
Else
'Filters Report by selected base and selected date range
On Error GoTo Err_runQuery_Click
'DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "rpt_DutyTime", acViewPreview, , "[tblBases] = '" & mybase & "' and [tblDate] between #" & Me.txtStartDate & "# and # " & Me.txtEndDate & "#"
DoCmd.Maximize
End If
Exit_runQuery_Click:
Exit Sub
Err_runQuery_Click:
MsgBox Err.Description
Resume Exit_runQuery_Click
End Sub