HighAndWilder
Active Member
- Joined
- Nov 4, 2006
- Messages
- 394
- Office Version
- 365
- Platform
- Windows
Hi All.
I'm creating a number of controls at runtime on a Userform.
This has been working fine and now I get an error message.
Compile error. Method or data member not found.
I've tried rebuilding the Userform a number of times and it is still causing an error.
It is the following line that causes the error. The 'Add' is highlighted so I assume that that the 'Add' method cannot found.
Set ctrl = Me.Controls.Add("Forms.CommandButton.1", "cmd" & strButtonPrefix & i, 1)
I have the necessary library selected.
Any ideas anybody?
Thanks.
I'm creating a number of controls at runtime on a Userform.
This has been working fine and now I get an error message.
Compile error. Method or data member not found.
I've tried rebuilding the Userform a number of times and it is still causing an error.
It is the following line that causes the error. The 'Add' is highlighted so I assume that that the 'Add' method cannot found.
Set ctrl = Me.Controls.Add("Forms.CommandButton.1", "cmd" & strButtonPrefix & i, 1)
I have the necessary library selected.
Any ideas anybody?
Thanks.
VBA Code:
Private Sub subCreateCommandButtonGrid()
Dim intLeft As Integer
Dim intHeight As Integer
Dim intWidth As Integer
Dim intCount As Integer
Dim intPerRow As Integer
Dim arrCaptions(1 To 26) As String
Dim i As Integer
Dim strButtonPrefix As String
Dim ctrl As Control
Dim intGap As Integer
Dim intCounter As Integer
Dim intOriginalLeft As Integer
intLeft = 10
intHeight = 35
intWidth = 35
intCount = 26
intPerRow = 8
strButtonPrefix="Alpha"
For i = 1 To 26
arrCaptions(i) = Chr(64 + i)
Next i
intOriginalLeft = intLeft
intGap = 2
For i = 1 To intCount
Set ctrl = Me.Controls.Add("Forms.CommandButton.1", "cmd" & strButtonPrefix & i, 1)
With ctrl
.TOP = intTop
.Left = intLeft
.Height = intHeight
.Width = intWidth
.Caption = arrCaptions(i)
End With
If (i Mod intPerRow) = 0 Then
intTop = intTop + intHeight + intGap
intLeft = intOriginalLeft
Else
intLeft = intLeft + intWidth + intGap
End If
Next i
End Sub