Changing a report with information from a form

R

Roger Withnell

In summary, I am opening a report with a sub in a form and trying to put
information from the form into the report.

I have built a public function in a module of the
report and call that function from the form sub. The simple test sub in the
form is:

DoCmd.OpenReport "Analysis report", acViewPreview
Reports![Analysis Report].SetAnalysisReport

The simple test function is:

Public Function SetAnalysisReport() As Variant
MsgBox (Me!Label5.Caption) 'Caption = Hello
Me!Label5.Caption = "Goodbye"
MsgBox (Me!Label5.Caption) 'Caption = Goodbye
End Function

The caption is changed but 'Hello' is still displayed on the report.

Many thanks in anticipation for your advice.
 
G

Guest

Put it into the Report_Open event?

Private Sub Report_Open(Cancel As Integer)
Me!Label5.Caption = "Goodbye"
End Sub

or, to pull the caption from a textbox on your form that opens the report:

Private Sub Report_Open(Cancel As Integer)
Me!Label5.Caption = [Forms]![yourForm]![txt1]
End Sub
 
R

Roger Withnell

Many thanks, Brian. Your a star.

Brian said:
Put it into the Report_Open event?

Private Sub Report_Open(Cancel As Integer)
Me!Label5.Caption = "Goodbye"
End Sub

or, to pull the caption from a textbox on your form that opens the report:

Private Sub Report_Open(Cancel As Integer)
Me!Label5.Caption = [Forms]![yourForm]![txt1]
End Sub


Roger Withnell said:
In summary, I am opening a report with a sub in a form and trying to put
information from the form into the report.

I have built a public function in a module of the
report and call that function from the form sub. The simple test sub in
the
form is:

DoCmd.OpenReport "Analysis report", acViewPreview
Reports![Analysis Report].SetAnalysisReport

The simple test function is:

Public Function SetAnalysisReport() As Variant
MsgBox (Me!Label5.Caption) 'Caption = Hello
Me!Label5.Caption = "Goodbye"
MsgBox (Me!Label5.Caption) 'Caption = Goodbye
End Function

The caption is changed but 'Hello' is still displayed on the report.

Many thanks in anticipation for your advice.
 

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