ADD LISTBOX, COMBOBOX, LABEL IN THE SAME USERFORM

E

Eddie_SP

In a multipage control, after clicking on a button, can I add a Listbox (or
any other object) without closing this multipage?


Example:

If Me.CommandButton1.Value = True Then
Listbox.Add
With Listbox
Width = X
Height = Y
Top = YY
Left = RR
End With


So... Is that possible?
 
D

Dave Peterson

I've always found it much, much easier to add the controls in design mode. Then
use code to toggle the visibility. (You could change the position if you needed
to.)
 
J

john

must confess never added a control on the fly before but had a quick play &
managed to get following to work. Maybe give you some ideas to develop
further.

Private Sub CommandButton1_Click()
Dim MyPage As MSforms.Page
Dim MyListBox As MSforms.ListBox


Set MyPage = MultiPage1.Pages(0)

Set MyListBox = MyPage.Controls.Add("Forms.ListBox.1")

With MyListBox

.Top = 10
.Left = 20
.Height = 50

End With

End Sub
 
E

Eddie_SP

Wow John, it started working...
I can go on from here now !

Thank you sir !

=)

Thank you Dave.
 
J

john

you are welcome.

if you want to add the control to a new page

just replace this line:

Set MyPage = MultiPage1.Pages(0)

with this

Set MyPage = MultiPage1.Pages.Add("Page" & MultiPage1.Pages.count + 1)

good luck.
 
Top