0
votes

I have a report that is dynamically generated depending on the button pressed on my main form, in order to change the filter, the query used, etc. I have DoCmd.Rename working to rename the report to the current (dynamic) report title. However, it appears that I cannot rename the report back to a generic name upon closing the report.

Using the Report_Close() event doesn't work; Access tells me the report is still open and therefore can't be closed. Using DoCmd.Close doesn't work either; I get Runtime error 2501 (The Close action was cancelled).

How can I rename this report after it's closed?

1
Why in the world do you think you need to RENAME the report? Why do you think you need to save the dynamically passed filtering, etc.?David-W-Fenton
Well, I am setting the recordset dynamically and whatnot. The problem is that when the report is saved (there is a command button to save as PDF without viewing the report first, for convenience, as there are like 16 different reports that are generated daily), the Save As... dialog defaults the filename to the generic report name (e.g. Report.pdf rather than "Incidents By Assignee.pdf"). If I could rename the actual Report object upon opening and rename it back to the generic upon closing, this would allow faster save-to-PDF functionality.ClairelyClaire
That's a TERRIBLE reason to rename the source report. Instead, you should figure out how to change the filename used for the PDF. That depends entirely on how you're accomplishing the SAVE AS PDF.David-W-Fenton
DoCmd.OutputTo acFormatPDF. The only way to specify the PDF name is to also specify the full path, which isn't going to work when multiple users are using this application.ClairelyClaire
If controlling the filename is a requirement for you, then you need to use a different method for outputting a PDF, such as PDFCreator. DoCmd.OutputTo is not a very robust way to do this kind of thing, as it is so limited (as you've discovered).David-W-Fenton

1 Answers

0
votes

Are you saying that each time someone changes the settings and opens a report, you want to save that as a new report in Access?

I wouldn't recommend this.
If the dynamically changed stuff are just things like filter and query, why not always use the same report and set the RecordSource dynamically?


EDIT:

Okay, now I understand what you actually want to do.
You can set the Caption property of the report at runtime in code:

Private Sub Report_Open(Cancel As Integer)
    Me.Caption = "Incidents By Assignee"
End Sub

You can also pass the text for the caption from your main form to the report:

Pass the text from the form in the OpenArgs parameter when opening the report:

DoCmd.OpenReport "YourReport", acViewNormal, , , , "Incidents By Assignee"

...and in the report, just set the Caption to OpenArgs if it's not empty:

Private Sub Report_Open(Cancel As Integer)

    If Nz(Me.OpenArgs) > "" Then
        Me.Caption = Me.OpenArgs
    End If

End Sub