PDA

View Full Version : Controls on the fly



CicoMico
06-26-2007, 11:53 AM
hey! i'm stuck again! i've designed userform (frmMy) with multipage (multiP). page1 contains frame (frameD). i want to populate this frame with labels, based on my worksheet. code:

Dim Labes As MSForms.Label

for x=15 to 1 step - 1
set Labes = frmMy.multiP.Pages(0).frameD.designer.controls.add("forms.label.1")
with Labes
.top = 20
end with
next x

all i get is error on set command - Object doesn't support this property or method. any help?? thanx

lucas
06-26-2007, 12:00 PM
Can I ask why your creating them on the fly...your asking for problems. Why not just put the label on the form where you want it and populate it based on your worksheet code?

CicoMico
06-26-2007, 12:04 PM
hi lucas :hi: the problem is, that amount of labels will change (based on sheet data) through time. user can add some data to sheet, and i want to display them on label.

lucas
06-26-2007, 12:06 PM
discussion:
http://www.vbaexpress.com/forum/showthread.php?t=11177&highlight=controls

CicoMico
06-26-2007, 11:27 PM
OK, thanx. i get it... but now, i have about 30 checkboxes and two problems arises:
a) how to automatically populate captions (yes, i can use checkbox.caption = cells("1","A"); but how to make it easier)
b) i want to check all of them, if they are clicked, and do some code...
any help?

sorry i'm newbie :banghead: so please have patience with me :dunno

geekgirlau
06-26-2007, 11:41 PM
9 times out of 10, if you have that many controls on a user form you could probably use a rethink on your design - could you post a sample workbook?

CicoMico
06-26-2007, 11:45 PM
unfortunately i can't. it's made for internal company purposes. but believe me, i have to have these checkboxes on my form. they are for selecting different input variables for calculations.. any more help?

geekgirlau
06-27-2007, 12:07 AM
Is there a naming convention that you've used for your checkboxes?

CicoMico
06-27-2007, 12:09 AM
CheckBox1, CheckBox2...

mdmackillop
06-27-2007, 12:14 AM
Private Sub UserForm_Initialize()
For i = 1 To 3
Me.Controls("Checkbox" & i).Caption = Cells(i, 1)
Next
End Sub

geekgirlau
06-27-2007, 12:20 AM
You could use something like the following, however there are a few assumptions:

The numbering of the checkboxes is consecutive, with no gaps in the numbering;
The number of the checkbox corresponds with the row on the sheet in some way (the code below assumes the data is in column A, with the caption for Checkbox1 in row 1, the caption for Checkbox2 in row 2 etc.)
Dim i As Integer


For i = 1 To 30
UserForm1.Controls("Checkbox" & i).Caption = SheetName.Cells(i, 1)
Next i

geekgirlau
06-27-2007, 12:21 AM
Curses, pipped at the post!

CicoMico
06-27-2007, 12:28 AM
wow! perfect! THANX!

Aussiebear
06-27-2007, 01:23 AM
Curses, pipped at the post!

Well if you had a social life...... this wouldn't have happened!!!:devil2:

mdmackillop
06-27-2007, 02:36 AM
Curses, pipped at the post!
I only did it for 3, so much quicker!

Norie
06-27-2007, 09:58 AM
Why not use a listbox?

You can set it's properties to display checkboxes next to each item and to allow multiple selection.