add controls on the fly/dynamically

jinx_uk_98

Board Regular
Joined
Jul 3, 2005
Messages
105
Hi All.

I use this code to rename the tabs of multipage control on a userform.

Sub page()

For Each Cell In Sheets("Data").Range("major_streams")
frm_daily_entry.MultiPage1.Pages.Add Cell.Text
Next

End Sub

The problem I have is that when creating the tabs on the fly I also have to create other controls on the fly too, specifically Labels & textboxes.

The Labels & Textboxes will be defined by looking up the caption of the current tab (on sheet1) and adding however many label/Textboxes that are required (one for every item under the heading on the sheet).

Anyone have any ideas?

thanks

Kevin
 

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Rijnsent

Well-known Member
Joined
Oct 17, 2005
Messages
1,298
Office Version
  1. 365
Platform
  1. Windows
Switching on/off

Hi Kevin,

sounds like a tough one... I think the easiest way around would be to create a userform, put the items (like boxes, buttons etc.) on their place and then use the code to change the caption, visability and whether it is switched on or not...
I don't know if you are familiar with Access, but I'm thinking off more or less the same idea as a standard created menu in Access (the Switchboard).

Would that help you?

Greetz,

Koen
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,100
Office Version
  1. 365
Platform
  1. Windows
Kevin

I'm not 100% sure what your question is but I think you probably want to look at the Add method of the Controls collection of the Userform/Page.

Also if you are adding the controls to the new pages of the multipage you should probably set a reference to the new page when you add it.
Code:
Dim mp As Page

    Set mp = MultiPage1.Pages.Add("New Page")
    mp.Controls.Add "Forms.Textbox.1"
 

Watch MrExcel Video

Forum statistics

Threads
1,119,264
Messages
5,577,060
Members
412,763
Latest member
sienweiw
Top