Open report problem

  • Thread starter Thread starter GZ
  • Start date Start date
G

GZ

Hi! On a report, I wrote code as following:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

Me.txtPaid = Forms!Invoice.txtPaid

If IsNumeric(Me.txtPaid) Then
If CCur(Me.txtPaid) > 0 Then Me.lblTitle = "Receipt"
Else
Me.lblTitle = "Invoice"
End If

End Sub


On a forms, I have a button, when clicked, it will open the report, and
according to data on the form, to change text of a label on the header of
the form, but this label title never change right away. I have to click
"Design" the report then reopen the report then the effect can be seen.

How to fix this problem and let user click the open report and directly see
what the report should be?

Thanks!

GZ
 
your button on the form is not triggering the code in the
report to run. the code should be in the on open event of
the reports properties.
 
Thanks for reply!
I think you are mention Report_Open event. Unfortunately, in this event
procedure, it's not allowed "to assign a value to this object".
I've copied the code to the Report_Open event, but got the above error
message. Any other choice?
Thanks!
GZ
 
I put the code [ Me.lblTitle = "Receipt"] into the following procedure:

Sub Detail_Print(),
Sub Detail_Format(Cancel As Integer, FormatCount As Integer),
Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

Actually, when open the report from a form, the code in above procedure of
the report module are executed. But the opened report still with blank or
sometimes old value "Invoice". I have to click "Design" the report then
using "Preview" to get the value shown correctly.

Ideally, it is supposed to put the code to Report_Open event ad Frank
suggested, but it is not allowed.

I've noticed that, when open the report from design view, the procedure [Sub
PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)] is
executed and the lblTitle has the value "Receipt" correctly. However,
without the code [ Me.lblTitle = "Receipt"] in this procedure instead in
other procedure, it is also shown correctly, if previewed from design view.

What's wrong? why the old value "Invoice" some times shown? Why only the
preview is working?

GZ
 
Back
Top