RAYLWARD102
Well-known Member
- Joined
- May 27, 2010
- Messages
- 529
I have a frame that I'm able to create dynamic buttons into it with VBA code.
At times, I want to clear the slate (the frame to be exact) but have had some issues. I originally used:
userform1.frame1.clear
Which seemed to work fine until I moved my project to another computer.
I then changed it to
Which works but I feel is not the correct way of handling the removal of controls.
How do I remove all controls from frame1.
Here is the code I used for creating the buttons.
At times, I want to clear the slate (the frame to be exact) but have had some issues. I originally used:
userform1.frame1.clear
Which seemed to work fine until I moved my project to another computer.
I then changed it to
Code:
For Each ctl In Userform1.frame1.Controls
ctl.Visible = False
Next ctl
Which works but I feel is not the correct way of handling the removal of controls.
How do I remove all controls from frame1.
Here is the code I used for creating the buttons.
Code:
For Each cell In spTY.Range("ak2:ak" & iRow).Cells
If cell.Value = "" Then GoTo nextitem
Set ctl = UserForm1.Frame1.Controls.Add("Forms.CommandButton.1")
ctl.Caption = cell.Value
ctl.Font.Size = 12 'SET FONT SIZE TO 14
ctl.BackStyle = 1
ctl.BackColor = &HFFC0C0
ctl.TabStop = False
If zx < 2 Then
ctl.Left = zx * 125 'adjust the width if you adjust this left. example: width 120 then left is 130
ctl.Top = zq * 26 'adjust the height if you adjust this top. example: height 30 then top is
Else:
zx = "0"
zq = zq + 1
ctl.Left = zx * 125
ctl.Top = zq * 26
End If
ctl.Font.Name = "Arial"
ctl.Font.Bold = True
ctl.Height = 24 '25
ctl.Width = 120 '110
ctl.WordWrap = True
ReDim Preserve CmdButtons1(1 To i + 1)
Set CmdButtons1(i + 1).CmdGroup1 = ctl
i = i + 1
z = z + 130
zx = zx + 1
nextitem:
Next cell