How to Change Report Title

aakwami

New member
Local time
Today, 14:01
Joined
Dec 17, 2012
Messages
8
I have a form with command button, when clicked it displays My report in Preview. I want to change the report title whenever i click a button from the form. I believe it is to do with VBA and am new in that. Can somebody help please. Thanks.
 
When you open a report using docmd one of the options is OpenArgs.

When you open the report, populate this with the name you want to appear - e.g. "New Report"

Next, open the report in design view and in the form Onload Event put the following:

Me.Caption=OpenArgs

Job done!
 
Hello aakwami, you can use the OpenArgs argument when you open the report and check in the Report_Load() event if there is something, if so change it else leave it as such..

It should be something along the lines of..
Code:
Private [COLOR=Blue]buttonToOpenReportName[/COLOR]_Click()
    DoCmd.OpenReport "[COLOR=Blue]reportName[/COLOR]", OpenArgs := "[COLOR=Blue]The title you wish to set[/COLOR]"
End Sub
On the Reoprt Load method you can check the open arg value,
Code:
Private Sub Report_Load()
    If Len(Me.OpenArgs & vbNullString) <> 0 Then
        Me.[COLOR=Blue]Auto_Header0.[COLOR=Black]Caption[/COLOR][/COLOR] = Me.OpenArgs
    End If
End Sub
Change the Blue Bits..
 
Last edited:
I have tried that, but the Report has no Onload Event
 
click in the small squar dot in the top left of the form design screen - next to where is says .|.1.|.2....
then click on the event tab
 
I'm trying to change the caption of a label I have in a report through VBA. I have this:
Reports!rptStaffLoan.lblLoan.Caption = "List of Staff with Car Loan"

If I place this line before the DOcmd.OpenReprot line, it bombs out because the report isn't opened. If I put the line after I open the report I can step through the line with no problem, but the caption doesn't change because the report is already opened.

Please, I need your help.
 
you have to put it in the reports on load event
 

Users who are viewing this thread

Back
Top Bottom