Edit Report label caption, from button on form

lovett10

Registered User.
Local time
Today, 06:15
Joined
Dec 1, 2011
Messages
150
I have a button (Command5) on form "Homepage", I want when i press it for it to open the report whilst also changing the caption on (Label34) on the report, to the same as (Text72) that is on the form.

Thanks in advanced
 
I have a button (Command5) on form "Homepage", I want when i press it for it to open the report whilst also changing the caption on (Label34) on the report, to the same as (Text72) that is on the form.

Thanks in advanced

If I understand you correctly, the main form has trouble talking to the report as it isn't open yet. I'm sure there are other ways to do this, but I would create an invisible text box on the 'homepage' form call txtNewLabelName. Add code to the OnClick event of Command5, that says:
me!txtNewLabelName="NewLabelTextHere"
DoCmd.OpenReport "yourReportNameHere", acViewReport


Then in the label.caption property in the report (or assigned by VBA) you enter:

=Forms!Homepage!txtNewLabelName


OR with vba in the reports OnLoad or OnCurrent event:

me!Labelname=Forms!Homepage!txtNewLabelName


Hope that helps.
 
As Chaos suggests use the reports OnLoad event but you do not need to use the invizible textbox, just reference Text72:D. The code needs to be Me!Label34.caption = Forms!Homepage!text72, so long as the form stays open.

You could also make use of the OpenArgs argument of the DoCmd.OpenReport method to pass the value to the report and pick that up in the OnLoad event

ALternatively, change Label34 to a textbox and set the ControlSource as = Forms!Homepage!text72
 
As Chaos suggests use the reports OnLoad event but you do not need to use the invizible textbox, just reference Text72:D. The code needs to be Me!Label34.caption = Forms!Homepage!text72, so long as the form stays open.

You could also make use of the OpenArgs argument of the DoCmd.OpenReport method to pass the value to the report and pick that up in the OnLoad event

ALternatively, change Label34 to a textbox and set the ControlSource as = Forms!Homepage!text72

lol whoops I missed that he had a control there already *mybad*
Having said that it's a good technique to remember when you're passing data you DON'T want the user to see.
 

Users who are viewing this thread

Back
Top Bottom