Thanks Fred.
That works but I was afraid of not having the form open when the report ran.
I ended up passing the dates as part of OpenArgs as:
DoCmd.OpenReport strDocName, acPreview, , strSQL, , txtBegDate & ";" &
txtEndDate
I then extracted the dates in the Report Activate event as:
Private Sub Report_Activate()
On Error GoTo ErrorHandler
If Not IsNull(Me.OpenArgs) Then
'Extract date range
Dim str As String 'passed arguments
Dim l As Integer 'length of passed string
Dim s As Integer 'positon of separator
Dim bd As String 'begin date
Dim ed As String 'end date
str = Me.OpenArgs
s = InStr(1, str, ";")
l = Len(str)
bd = (Left(str, s - 1))
ed = (Right(str, l - s))
txtDateRange = "All checks from: " & bd & " to: " & ed
Else
txtDateRange = "All checks displayed"
End If
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number _
& ": Description: " & Err.Description
End Sub
This seems to work well from what I've tested so far.
Just out of curiosity, I still would be interested in knowing:
1.How to use a Domain Aggregate function to read the Min/Max value in the
recordset that serves as a report's record source.
(e.g, something like: =DMax([OrderDate],[qr_Orders]))
2. How to test if a particular form is open.
Dave,
You've gone to an awful lot of work to do a very simple thing.
The problem with using the report's Activate event is that the
Activate event fires only when the report is previewed, not when
printed directly without preview.
Here is the usual method of passing a form control value as a
parameter to a query (and to the report header) which is being used as
the record source for a report.
I'll use a query that just asks for a range of dates, but it could
also include a company name, or product, etc.
Create an unbound form.
Add 2 text controls.
Name one txtStartDate.
The other txtEndDate.
Set their format property to Short Date.
Add a command button.
Code it's Click event:
Me.Visible = False
Name this form 'ParamForm'.
As Criteria in the query, write, on the DateField criteria line:
Between forms!ParamForm!txtStartDate and forms!ParamForm!txtEndDate
Next code the Report's Open event:
DoCmd.OpenForm "ParamForm", , , , , acDialog
Code the Report's Close event:
DoCmd.Close acForm, "ParamForm"
Add an unbound control to the Report Header to display the dates.
Set it's Control Source to:
"Some text " & forms!ParamForm!txtStartDate & " and " &
forms!ParamForm!txtEndDate
If you wanted to format the dates, when displayed in the report,
differently than when input in the form, you could use:
="Some text " & format(forms!ParamForm!txtStartDate,"mmmm d, yyyy") &
etc.
to show it as "Some text June 20, 2004" etc. instead of "Some text
6/20/2004"
When you are ready to run the report, open the Report.
The report will open the form. enter the date range wanted. Click the
command button. The report will display. The date range will appear in
the header. When you close the report, it will close the form.