mardi 24 mai 2016

Dynamically define the events of the checkboxes in VBA

I have defined dynamically the checkboxes for my UserForm. See the code:

If rs.EOF = False Then
    i = 1
    Do Until rs.EOF Or i = 6
        With frmOne.Controls("Version" & i)
            .Visible = True
            .Caption = rs!versNo & "#" & rs!Vers_From
            .tag = rs!versNo & "_" & rs!noID & ".pdf"
        End With
        i = i + 1
        rs.MoveNext
    Loop
End If

Well, for these checkboxes I need a "Click"-Event. For example:

Private Sub Version1_Click()
   If FilterOk = True Then
       VersNr = Mid(frmOne.Version1.tag, 1, InStr(frmOne.Version1.tag, "_") - 1)
       Call funcVersion
       Exit Sub
   End If
   ...
End Sub

How can I make dynamic? I don't need a CommandButton for that. That means, when the user click on the Checkbox then the eventhandler starts.




Aucun commentaire:

Enregistrer un commentaire