The default value of a report parameter may be changed at run time using the report parameters collection. The following code samples show how to set the current date as the default value for a report parameter.
Sample query:
“Select * from MyTable where SomeDate>=#<%D1%># and SomeDate<=#<%D2%>#”
To use the code behind the report, place code like the following in the ReportStart event.
Private Sub ActiveReport_ReportStart() Me.Parameters(0).DefaultValue = Date$ Me.Parameters(0).Prompt = "Start date" Me.Parameters(1).DefaultValue = Date$ Me.Parameters(1).Prompt = "End date" End Sub
To use the code behind a form, place code like the following in the Form Load event.
Private Sub Form_Load() Dim ar As New ActiveReport1 ar.Parameters(0).DefaultValue = Date$ ar.Parameters(0).Prompt = "Start date" ar.Parameters(1).DefaultValue = Date$ ar.Parameters(1).Prompt = "End date" ar.Show End Sub
To use an RPX file with script, place code like the following in the report's script.
Sub OnReportStart rpt.Parameters(0).DefaultValue = Date rpt.Parameters(0).Prompt = "Start date" rpt.Parameters(1).DefaultValue = Date rpt.Parameters(1).Prompt = "End date" End Sub