Can't change label header with OnOpen

  • Thread starter Thread starter insomniux
  • Start date Start date
I

insomniux

Hi,
I am using a generic report, of which I need to change the header on
the fly. I don't mind if the header text is in a label of a textfield.
When I try to set Me.HeaderLabel = "NewValue" (where HeaderLabel is the
name of the textfield in the Report) in OnOpen, I get an error
messages. Is there a way to modify the value of controls on the fly?
I'm using version 2000 SP3.
Thanks.
 
Run the code in the On Format event of the section containing the control.
This assumes the text box is unbound.
 
If you use a text box, set the ControlSource property ...

Me.HeaderLabel.ControlSource = "=""New Value"""

Note the multiple quotes.

If you use a label, set the Caption property ...

Me.Label1.Caption = "New Value"
 
insomniux said:
I am using a generic report, of which I need to change the header on
the fly. I don't mind if the header text is in a label of a textfield.
When I try to set Me.HeaderLabel = "NewValue" (where HeaderLabel is the
name of the textfield in the Report) in OnOpen, I get an error
messages. Is there a way to modify the value of controls on the fly?
I'm using version 2000 SP3.


Sure, it's just that Open event is to early to change the
Value property. If you used a label control, then you can
change it's Caption property in the Open event.

To use a text box, use the report header's format event to
set its value.
 
Duane, Marshall and Brendan, thanks for your help.
I've tried the three options and all three work. Still 've some
additional comments:

- Me.HeaderLabel.ControlSource = "=""New Value""" (in OnOpen context):
does work but not if "New Value" value is stored in a variable. The
ControlSource property is not shown on the OnOpen event.

- Me.Label1.Caption = "New Value" (in OnOpen context): does work, but
in the contents of my variable there is an "&" sign, which is ignored
(unless I replace it with "&&"). The Caption property is not show in
the OnOpen event.

- Me.Headerlabel = MyVariable (in OnFormat context) works (control =
textbox).

Thanks again.
 
Responses in-line below.
--
Brendan Reynolds
Access MVP

insomniux said:
Duane, Marshall and Brendan, thanks for your help.
I've tried the three options and all three work. Still 've some
additional comments:

- Me.HeaderLabel.ControlSource = "=""New Value""" (in OnOpen context):
does work but not if "New Value" value is stored in a variable.

Dim strNewValue As String

strNewValue = "New & Value"
Me.Text0.ControlSource = "=""" & strNewValue & """"
The
ControlSource property is not shown on the OnOpen event.

You mean in the 'IntelliSense' list? As far as I am aware, the ControlSource
property is not shown in that list in any report event procedure. There are
other control properties that are not shown in that list also. None of the
font properties are shown, for example - FontName, FontSize, FontBold, etc.
But that's just a limitation of the 'IntelliSense' feature. The
'IntelliSense' list is in not a reliable indicator of what properties are
available.
- Me.Label1.Caption = "New Value" (in OnOpen context): does work, but
in the contents of my variable there is an "&" sign, which is ignored
(unless I replace it with "&&").

You always have to double-up ampersand characters in labels, regardless of
how you set the property, programatically or using the UI at design time.
This is because the ampersand is used to define shortcut keys in form
labels. In report labels, shortcut keys are inoperative, but you still have
to double up the ampersand characters. You can do it programatically using
the Replace function ...

Me.Label1.Caption = Replace(strNewValue, "&", "&&")
 
Back
Top