I have a button on a form that passes parameters to a query and opens a report. The code is listed below (someone helped me with this a long time ago and I kept it and reuse it). This works without a problem but what I need to do is also pass [dtmStartDate] and [dtmEndDate] which both get passed to [dtmSessionDate] in the query to the report that is opened.
Since both fields are being passed to the field [dtmSessionDate] in the query I don’t know what I need on my report or in the code to make it show up like the following: “From Period: [dtmStartDate] To Period: [dtmEndDate] on my report.
Can anyone help me? Thanks in advance.
Since both fields are being passed to the field [dtmSessionDate] in the query I don’t know what I need on my report or in the code to make it show up like the following: “From Period: [dtmStartDate] To Period: [dtmEndDate] on my report.
Can anyone help me? Thanks in advance.
Code:
Private Sub cmdApplyFilter_Click() Dim strFilter As String Dim dtmStartDate As Date Dim dtmEndDate As Date 'Location If Not IsNull(Me.cboLocation) Then strFilter = strFilter & " AND txtCity=""" & Me.cboLocation & """ " End If 'Supervisor Name If Not IsNull(Me.cboSupervisorName) Then strFilter = strFilter & " AND txtSupervisorName=""" & Me.cboSupervisorName & """ " End If 'Begin and End Dates If Not (IsNull(Me.dtmStartDate) Or Me.dtmStartDate = "") Then strFilter = strFilter & " AND (dtmSessionDate) Between #" & Format(Me.dtmStartDate, "mm/dd/yyyy") & "# AND #" & Format(Me.dtmEndDate, "mm/dd/yyyy") & "#" End If 'If the report is closed, open the report If SysCmd(acSysCmdGetObjectState, acReport, "rptCallDetailsForAllAgentsBySupervisor") <> acObjStateOpen Then DoCmd.OpenReport "rptCallDetailsForAllAgentsBySupervisor", acPreview End If 'if report was open, use filter With Reports![rptCallDetailsForAllAgentsBySupervisor] .Filter = Mid(strFilter, 6) .FilterOn = True End With End Sub
Comment