jeudi 23 mars 2017

Excel VBA Userform CheckBoxes Access

I'm programmatically creating a userform based on number of rows in a sheet range (currently set to a fixed number for testing). Then the user checks the boxes they want to check and clicks the command button.

The userform, as run with the code below, has one command button and one checkbox manually added. The other checkboxs is added programmatically. I can't figure out how to get the value from the checkbox created problematically. I just get an error that "testbox" is not defined. I know I'm missing something simple...

Any thoughts? Thank you!

Option Explicit

Private Sub updateTablesBtn_Click()
    If CheckBox1.Value = True Then
        MsgBox "true"
    End If

    If testBox.Value = True Then
        MsgBox "true"
    End If
End Sub

Private Sub UserForm_Initialize()
    Dim chkBox As MSForms.CheckBox

    With formTableUpdate
        .Width = 150
        .Height = 200 '15 + 20 * (noOfVariants + 1) + 30
    End With

    Set chkBox = formTableUpdate.Controls.Add("Forms.CheckBox.1")
    With chkBox
        .Name = "testBox"
        .Caption = "test"
        .Left = 5
        .Top = 10
    End With

    With updateTablesBtn
        .Caption = "Update Tables"
        .Height = 25
        .Width = 76
        .Left = 38
        .Top = 30
    End With

End Sub




Aucun commentaire:

Enregistrer un commentaire