Many thanks for your reply. I was trying to find a balance between providing enough info for the context and overloading the first post with confusing detail.
Operating sequence
1: The report is opened from a switchboard menu item, and then it opens the form (if not already open);
2: The form controls set up the filter and then reopen the report;
3: Repeat 2 as often as necessary;
4: The form has a button which closes the report (if not closed by its own close button) and then closes the form.
Originally Posted by
June7
Why does the form name need to be dynamic? Is report opened from more than one form?
I can anticipate a situation where the report could be called from another form, eg when the beneficiary is the criteria instead of the date. However, I haven't thought through the details of this yet and it may be that we go down a separate route.
Originally Posted by
June7
strFilter is a variable or a textbox on form?
strFilter is a variable which is declared and populated in the form, in this sequence
Code:
Option Explicit
Option Compare Database
Private Const strFrmName As String = "fS1DateSelector" 'parameter form
Private Const strQryName As String = "qAvizDataAll" 'data source query
Public strRptName As String 'report name
Public intFirstDate As Date 'first date
Public intFinalDate As Date 'final date
Public strFilter As String 'assembled filter
------------------------------------------
Private Sub cmdApplyFilter_Click()
' assemble the filter using the date ranges
strFilter = "[data] between [forms].[" & strFrmName & "].[firstdate] and [forms].[" & strFrmName & "].[finaldate]"
' If the report is open then close it. Reopen the report with new filter.
If SysCmd(acSysCmdGetObjectState, acReport, strRptName) = acObjStateOpen Then
DoCmd.Close acReport, strRptName
End If
DoCmd.OpenReport strRptName, acViewPreview, strFilter
End Sub
Originally Posted by
June7
Use the WHERE CONDITION argument of OpenReport and the Me.Filter code is not needed.
DoCmd.OpenReport "reportname", , , strFilter
Comparing your code with my version above, it seems that I have confused FilterName and WhereCondition, and I need another comma.
Do I still need the 'FilterOn=True' statement when using that process?
I'll come back to the Reports! context described in the first post in a separate post in order to avoid prolonging this one.
Many thanks for your assistance, not just with this but also with your responses to other questions, which I have read 'on the quiet'.