simoncpage
Programmer
Is there anyway in VBA to create Arrays of checkboxes, I have no problem in VB6 but how do I do this in VBA. Im stuck and any help would be appreciated thanks
Simon
Simon
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Option Explicit
Private maChkBoxes(1 To 3) As Object
Private WithEvents MyCommandButton As CommandButton
Private Sub MyCommandButton_Click()
Dim i As Long
Dim sMsg As String
For i = 1 To 3
sMsg = sMsg & maChkBoxes(i).Caption & " is " & _
IIf(maChkBoxes(i).Value, "", "not ") & _
"checked" & vbCrLf
Next i
MsgBox sMsg
End Sub
Private Sub UserForm_Initialize()
Dim i As Long
Set MyCommandButton = Controls.Add("Forms.CommandButton.1", "MyCommandButton")
MyCommandButton.Top = (Me.InsideHeight - MyCommandButton.Height) / 2
MyCommandButton.Left = (Me.InsideWidth - MyCommandButton.Width) / 2
MyCommandButton.Caption = "Click me!"
MyCommandButton.Visible = True
For i = 1 To 3
Set maChkBoxes(i) = Controls.Add("Forms.CheckBox.1", "MyChkBox" & i + 1)
maChkBoxes(i).Top = (i - 1) * maChkBoxes(i).Height
maChkBoxes(i).Caption = "Box " & i
maChkBoxes(i).Visible = True
Next i
End Sub