Create new label using VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Is it possible to create a label in VBA? I know that I can create the labels
first and set its visible property. But I'd like to know if I can create it
on the fly using VBA.
Any pointers would be very much appreciated. Thanks.
 
If you have the form open in *design* view, you can use the CreateControl
method to create a control of type acLabel, and specify the name of the
parent control (what you want it attached to.)

This is useful only to help you develop a database, or if you are writing
wizards for people to create their own forms. If you are developing for
other users, you will always want to give them an MDE, and so this approach
is not suitable.
 
We don't know if Samatha is referring to a form or report. The Me.Print
method can be used in a report to add text virtually anywhere on the report.
 
Thanks Duane.

I wondered about the context too, and made an assumption based on the group
name.
 
Thanks to both Allen and Duane. I want to create a label in a form, when the
form in is run mode and not design. I basically want to show a short list
with labels based on the selections made by the user. There are only 2
results: either 3 or 4 labels to show. I guess I can create the labels and
then enable or disable the visible property. I thought I'd explore other
options, like creating a label during runtime by writing code. Is this
possible? thanks again.
 
No. You can only CreateControl() in Design view.

I would never consider taking that approach, as it stops you generating an
MDE.
 
Back
Top