stDocName = Me.ReportName
stFiscalQtr = "FiscalQtr=" & Me.FiscalQtr
DoCmd.OpenReport stDocName, acPreview, , stFiscalQtr
So, can we assume that in both reports, there is a field (column) called
fiscalQtr
And, this field is a text field.
That being the case, your code should read:
stDocName = Me.ReportName
stFiscalQtr = "FiscalQtr = '" & Me.FiscalQtr & "'"
DoCmd.OpenReport stDocName, acPreview, , strFiscalQtr
note how we had to surround the text value with quotes:
stFiscalQtr = "FiscalQtr = ' " & Me.FiscalQtr & " ' "
The above has extra spaces for reading in this post..but, you would remove
the spaces, and
use:
stFiscalQtr = "FiscalQtr = '" & Me.FiscalQtr & "'"
I really don't know how to apply the filter in the procedure.
The report form already has a filter. Do I need a function?
do you mean that the report already open, and has a filter?
Are we to assume that the report stays open, and additional filters are to
be applied? (note: as a general rule, you likely should setup the criteria
for the report...allow user to open the report...the view it...maybe print
it..and then close the report to return back to the prompt screen. This
generally a MUCH better approach then applying multiple filters to a open
report over time...I don't recommend doing that, and it tends to confuse
users..and worse....is harder to write).
However, I think your case...you do want to keep the report open...and add
*more*/additional filter to the report?
Note that you have two choices on how to restrict data when opening a
report:
You can use the "where" clause of a report. This is generally what most use
to "pass" restring critea to a report. Also, the 'where' clause can't be
changed after a report opens. note that using the "where" clause also saves
you having to code the "filter on" stuff that you have to do with a filter.
So, use the where clause to restrict the report. Of course, after the report
is open, if you need additional filtering, then you have to use the filter
command...and, you do NOT want to use the openReport on a report that is
already open! So, you code should likely check if the report is already open
if you plan to add additional filter to that report.
It should be noted that this 'where' clause actually does become the filter
setting of the report after it opens. As a general rule, we thus use the
where clause to restrict a report, and use the filter option if we need to
change a ALREADY OPEN report. Other then this issue, the filter, and "where"
clause are much the same. But, the filter tends to be used AFTER the report
opens..., and "where" is applied during the reports opening.
So, are we to assume the report is already open..and you want to apply
additional filters?
This is doable, you have to pull out the reports current filter, and then
add on the criteria form your form..and then stuff the filter back into the
report. However, what happens if the user closes that form..but not the
report..and then you open up the form...(the report will still be
opened..and have its existing filters -- this is much why I was suggesting
if you can have the report closed after the user is done viewing...and then
additional filters are added...and then the report is re-opened. (you can
force this by making the report modal).
You can well keep the report open, but just some extra caution need be taken
(for example, when you close that form...you might have it close the report
if it is also open).