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.
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
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.