Report Label Caption Property at Runtime

J

Jake

I would like to give a user the ability to set the caption for a report at
runtime, or in other words give the user the ability to change the title of
the report header.
I have a form that allows the user to enter a report title into a text box.
How can I make this entry the title for the report?
Thanks
 
D

Duane Hookom

You can use code in the On Open event of the report like:

Private Sub Report_Open(Cancel As Integer)
On Error Resume Next
Me.Caption = Forms!frmSetReportTitle.txtRptTitle
End Sub
 
J

Jake

Thanks Duane,
This changes the caption in the title bar, but I want to change the caption
property for a label control on the report.
I should have provided more detail perhaps.
This is the code I've tried:
Private Sub btnOK_Click()
Select Case Frame9
Case Is = 0
DoCmd.OpenReport "rptAWM525PhaseTwo1", acViewPreview, , "ysnapplicability="
rptAWM525PhaseTwo1.Label8.Caption = Forms!frmForQueryPhaseTwo.strReportTitle
DoCmd.Maximize
Exit Sub
Case Is = 1
DoCmd.OpenReport "rptAWM525PhaseTwo1", acViewPreview, , "ysnapplicability=1"
rptAWM525PhaseTwo1.Label8.Caption = Forms!frmForQueryPhaseTwo.strReportTitle
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "rptAWM525PhaseTwo1", acViewPreview
rptAWM525PhaseTwo1.Label8.Caption = Forms!frmForQueryPhaseTwo.strReportTitle
DoCmd.Maximize
End Select
End Sub
This code lets report display appropriate records based on applicability.
I'm trying to set the report Label8.caption to the forms text box,
strReportTitle.
Am I putting the code in the wrong spot or is the code faulty? I get a
runtime error 424 object required.
Thanks very much!
 
D

DebbieG

Private Sub btnOK_Click()
Select Case Frame9
Case Is = 0
DoCmd.OpenReport "rptAWM525PhaseTwo1", acViewPreview, ,
"ysnapplicability= " 'missing something here
DoCmd.Maximize
Case Is = 1
DoCmd.OpenReport "rptAWM525PhaseTwo1", acViewPreview, ,
"ysnapplicability=1"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "rptAWM525PhaseTwo1", acViewPreview
DoCmd.Maximize
End Select
End Sub

In your report properties, On Open:
Me.Label8.Caption = Forms!frmForQueryPhaseTwo!strReportTitle


| Thanks Duane,
| This changes the caption in the title bar, but I want to change the
caption
| property for a label control on the report.
| I should have provided more detail perhaps.
| This is the code I've tried:
| Private Sub btnOK_Click()
| Select Case Frame9
| Case Is = 0
| DoCmd.OpenReport "rptAWM525PhaseTwo1", acViewPreview, ,
"ysnapplicability="
| rptAWM525PhaseTwo1.Label8.Caption =
Forms!frmForQueryPhaseTwo.strReportTitle
| DoCmd.Maximize
| Exit Sub
| Case Is = 1
| DoCmd.OpenReport "rptAWM525PhaseTwo1", acViewPreview, ,
"ysnapplicability=1"
| rptAWM525PhaseTwo1.Label8.Caption =
Forms!frmForQueryPhaseTwo.strReportTitle
| DoCmd.Maximize
| Case Is = 2
| DoCmd.OpenReport "rptAWM525PhaseTwo1", acViewPreview
| rptAWM525PhaseTwo1.Label8.Caption =
Forms!frmForQueryPhaseTwo.strReportTitle
| DoCmd.Maximize
| End Select
| End Sub
| This code lets report display appropriate records based on applicability.
| I'm trying to set the report Label8.caption to the forms text box,
| strReportTitle.
| Am I putting the code in the wrong spot or is the code faulty? I get a
| runtime error 424 object required.
| Thanks very much!
|
|
| | > You can use code in the On Open event of the report like:
| >
| > Private Sub Report_Open(Cancel As Integer)
| > On Error Resume Next
| > Me.Caption = Forms!frmSetReportTitle.txtRptTitle
| > End Sub
| >
| >
| > --
| > Duane Hookom
| > MS Access MVP
| >
| >
| > | >>I would like to give a user the ability to set the caption for a report
at
| >>runtime, or in other words give the user the ability to change the title
| >>of the report header.
| >> I have a form that allows the user to enter a report title into a text
| >> box. How can I make this entry the title for the report?
| >> Thanks
 
J

Jake

thanks! Everything you mentioned was correct and it now works great!
needed the ! in Forms!frmForQueryPhaseTwo!strReportTitle
and a "0" for case 0
much appreciated!
 
K

Ken Snell [MVP]

Sometimes, controls are not fully instantiated in the Open event of a
report, so it's also good practice to use the Format event of the section of
the report that contains the control, and then run code similar to what
DebbieG posted for the Open event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top