I have a form that contains parameters for a report. After the user clicks Preview I have code that set's the Where clause for the report's record source. Once the report opens I close the parameter form. However, the user enters values on the parameter form that I want to display on the report (StartDate and EndDate, specifically). But because I close the parameter form (otherwise it'd be in the way of the report) I lose those values and they don't render on the report. So I thought I could store them in a global variable that I can then call in the report's header format event. This is what I have:
Parameter Form:
My report's format header event:
The issue is that when I debug my code, it doesn't recognize the global variables gstrStartDate and gstrEndDate in my report's header format code above. Error is "Variable not defined". What I don't understand is that I did define it as global variable in my cmdPreviewRepor t sub at the top so why isn't it recognizing it?
Parameter Form:
Code:
Option Compare Database Public gstrStartDate As String Public gstrEndDate As String Option Explicit Private Sub cmdPreviewReport_Click() gstrStartDate = Me.txtStartDate gstrEndDate = Me.txtEndDate ...more code... DoCmd.OpenReport "r_FamStmt", acViewPreview, WhereCondition:=strWhere DoCmd.Close acForm, "f_ParamFamStmt" End Sub
Code:
Private Sub FamilyIdGroupHeader_Format(Cancel As Integer, FormatCount As Integer) Me.txtReportingPeriod = "Reporting Period: " & gstrStartDate & " to " & gstrEndDate End Sub
Comment