MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Creating Controls at Runtime on UserForm

  Asked By: Daisy    Date: Jan 06    Category: MS Office    Views: 2053

I'm trying to create a Label and add it to a UserForm at runtime

Dim lbl as MSForms.Label 'it wouldn't let me use Label by it self
'got a type mismatch
set lbl = MyForm.Controls.Add("Forms.Label.1","myLabel",True)
with lbl
.Top = 10
.Left = 10
.Height = 15
.Width = 15
end with

The form displayed but with no label..



1 Answer Found

Answer #1    Answered By: Gilbert Moore     Answered On: Jan 06

Try :

Private Sub UserForm_Initialize()
Dim lbl As Control 'dim as Control or Forms.Label
Set MyForm = UserForm1
Set lbl = MyForm.Controls.Add("Forms.Label.1", "myLabel", True)
With lbl
.Top = 10
.Left = 10
.Height = 15
.Width = 25 'made it wider
.Caption = "TEST" 'write something
End With
End Sub

Didn't find what you were looking for? Find more on Creating Controls at Runtime on UserForm Or get search suggestion and latest updates.