Hello,
i have a form that counts the lines in a spreadsheet then adds that amount of textboxes and command buttons during Userform_Initialize(). the textboxes cant be referenced with their name but can be with .Controls(). my buttons on the otherhand are not generating Click events, so i cant get them to run any macros. anyone know how i can get them to run a macro? the code i am using is below. AddRow() is called by the userform_inialize()
when i want the button named btnMS1 to run a macro i would normally use:
any help would be appreciated as i cant seem to find any info on google.
-luke
i have a form that counts the lines in a spreadsheet then adds that amount of textboxes and command buttons during Userform_Initialize(). the textboxes cant be referenced with their name but can be with .Controls(). my buttons on the otherhand are not generating Click events, so i cant get them to run any macros. anyone know how i can get them to run a macro? the code i am using is below. AddRow() is called by the userform_inialize()
Code:
Private Sub AddRow()
Dim tbArea As Object 'the textbox for area
Dim tbJumbo As Object 'the textbox for the jumbo
Dim tbHeading As Object 'the textbox for heading
Dim tbStatus As Object 'the textbox for headings status
Dim tbDesc As Object 'the textbox for headings description
Dim tbMS As Object 'the textbox for mapped and sampled field
Dim btnMSbutton As Object 'the mapped sample button
Dim cbCheckRemove As Object 'the check remove checkbox
intcontrolcount = intcontrolcount + 1 'used to increment the controls number
Set tbArea = Me.frHeadings.Controls.Add("forms.textbox.1", "txtArea" & intcontrolcount, True)
Set tbJumbo = Me.frHeadings.Controls.Add("forms.textbox.1", "txtJumbo" & intcontrolcount, True)
Set tbHeading = Me.frHeadings.Controls.Add("forms.textbox.1", "txtHeading" & intcontrolcount, True)
Set tbStatus = Me.frHeadings.Controls.Add("forms.textbox.1", "txtStatus" & intcontrolcount, True)
Set tbDesc = Me.frHeadings.Controls.Add("forms.textbox.1", "txtDesc" & intcontrolcount, True)
Set tbMS = Me.frHeadings.Controls.Add("forms.textbox.1", "txtMS" & intcontrolcount, True)
Set btnMSbutton = Me.frHeadings.Controls.Add("forms.commandbutton.1", "btnMS" & intcontrolcount, True)
Set cbCheckRemove = Me.frHeadings.Controls.Add("forms.checkbox.1", "chkCheckRemove" & intcontrolcount, True)
'omitted properties of other controls normally sits here
With btnMSbutton
.BackColor = &H8000000F
.Cancel = False
.Height = 13
If (intcontrolcount Mod 2) = 0 Then 'offsets the buttons to make it more readable
.Left = 600
Else: .Left = 570
End If
.Top = 13 * (intcontrolcount - 1)
.Width = 25
'.tabindex=
End With
End Sub
when i want the button named btnMS1 to run a macro i would normally use:
Code:
Private Sub btnMS1_Click()
intControlNumber = 1 '
Application.Run "subRoutines.ButtonMapped"
End Sub
any help would be appreciated as i cant seem to find any info on google.
-luke