Set label caption based on text box value in Report !

siamandm
BronzeLounger
Posts: 1211
Joined: 01 May 2016, 09:58

Set label caption based on text box value in Report !

Post by siamandm »

hello

how to set a caption of a label based on the value of a text box in a report ?

regards

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Set label caption based on text box value in Report !

Post by HansV »

Let's say that the label is in the Detail section of the report.
Create an On Format event procedure for this section:

Code: Select all

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Me.ThisLabel.Caption = Me.ThatTextBox
End Sub
where ThisLabel and ThatTextBox are the names of the label and text box, respectively.

Remark: the code will work when you display the report in Print Preview or print it. It won't work if you display the report in Layout View or in Report View.
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1211
Joined: 01 May 2016, 09:58

Re: Set label caption based on text box value in Report !

Post by siamandm »

Thanks a lot ... working very well

Regards