开发者

Access 2007 VBA - Rename report upon closing it?

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?


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜