Changing a report with information from a form

  • Thread starter Thread starter Roger Withnell
  • Start date Start date
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.
 
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
 
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.
 
Back
Top