Add a label at runtime

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

Guest

Hi,

Can anyone tell me how I can add a label to a form at runtime.


Regards,
Ron.
 
I don't know if you can do this, but you could create a label beforehand
with a blank caption then use Label1.Caption = "Test label" at runtime to
populate it.
 
Dim newCtl As msforms.Control
Set newCtl = Me.Controls.Add("Forms.Label.1")
newCtl.Caption = "New Label"

With newCtl
.Left = 100
.Top = 50
.Visible = True
End With

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
If by form, you mean a userform:

Private Sub UserForm_Initialize()
Dim LBL As MSForms.Label
Set LBL = Controls.Add("Forms.Label.1", "Lable2", True)
LBL.Top = 5
LBL.Left = 5
LBL.Caption = "abcd"

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top