Howdy -
I have several dynamic reports which use a form to filter the results. One such filter is the date range of the report. I set up a nifty way so the top of the report displays the date range entered (or a default date range if dates are not used in the filter). However, once I close that filter form, the dates in the report header no longer work (because they were pulling from the opened form).
Is there a way I can store those dates differently, so they can still be used after the form closes? Is there a better way to set the control source for the header textbox? I played with a few options yesterday but could not figure it out. Some code below:
Current code that sets the control source: (Before yesterday, I just had this entered directly as the control source in the properties of the report.)
Function referenced in the above code ("GetEndAll" is similar):
One of my other efforts, which creates a string when the "Apply Filter" button is pressed on the filter form, and then attempts to use that string to set the control source. However, I just get one of those "enter parameter" boxes pop up when I do this. Maybe I'm missing something in the syntax? Or is it not possible to use a string like this in my control source?
Thanks for any input. I am not a coder whatsoever and most of the VBA I use was taken from various sources, so please include example codes or detailed explanations of what those commands and whatnot all mean!
I have several dynamic reports which use a form to filter the results. One such filter is the date range of the report. I set up a nifty way so the top of the report displays the date range entered (or a default date range if dates are not used in the filter). However, once I close that filter form, the dates in the report header no longer work (because they were pulling from the opened form).
Is there a way I can store those dates differently, so they can still be used after the form closes? Is there a better way to set the control source for the header textbox? I played with a few options yesterday but could not figure it out. Some code below:
Current code that sets the control source: (Before yesterday, I just had this entered directly as the control source in the properties of the report.)
Code:
Reports!rptProgramStatsAll.Header_Label.ControlSource = "='Program Statistics between ' & GetStartAll() & ' and ' & GetEndAll()"
Function referenced in the above code ("GetEndAll" is similar):
Code:
Public Function GetStartAll()
If CurrentProject.AllForms("frmFilterProgStats").IsLoaded Then
If IsNull(Forms!frmFilterProgStats.[StartDate]) Then
GetStartAll = GetFirstDate()
Else
GetStartAll = Forms![frmFilterProgStats]![StartDate]
End If
Else
'I had some code here, but deleted it so now it just returns nothing if the form is not loaded.
End If
End Function
One of my other efforts, which creates a string when the "Apply Filter" button is pressed on the filter form, and then attempts to use that string to set the control source. However, I just get one of those "enter parameter" boxes pop up when I do this. Maybe I'm missing something in the syntax? Or is it not possible to use a string like this in my control source?
Code:
strHeaderLabel = "='Program Statistics between ' & strStartDate & ' and ' & strEndDate"
Reports!rptProgramStatsAll.Header_Label.ControlSource = strHeaderLabel
Thanks for any input. I am not a coder whatsoever and most of the VBA I use was taken from various sources, so please include example codes or detailed explanations of what those commands and whatnot all mean!