Adding Checkboxes to a Form

B

Bill

Hello All,
Is there a way to use VBA to add a certain number of checkboxes (or anything
else) to a userform? For example, I may need anywhere from 3 to 7
checkboxes on a userform. I would prefer to build just one instead of 5
different userforms.

Thanks for the help.

Bill
 
D

Dave Peterson

I find it much simpler to add all the controls I need to the userform.

But hide them until they're needed (.visible = false)
 
D

Die_Another_Day

Sub SpawnCheckBoxes()
Dim CheckBoxTotal As Long
Dim cnt As Integer
Dim myCB As Control

CheckBoxTotal = Application.InputBox("How many CheckBoxes would you
like?", "Creating CheckBoxes...", 3, , , , , 1)
For cnt = 1 To CheckBoxTotal
Set myCB = frmMyForm.Controls.Add("Forms.Checkbox.1", "myCB" &
cnt)
With myCB
.Left = 0
.Top = (cnt * 15) - 15
.Object.Caption = "Hello From CheckBox" & cnt
.Object.Value = True
.Object.AutoSize = True
End With
Next
frmMyForm.Show
End Sub

Try that post back if you have problems

HTH

Die_Another_Day
 

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

Top