Click Event in Class Module Not Firing

后端 未结 2 999
遥遥无期
遥遥无期 2020-12-20 02:56

I have a user form that displays line-by-line validation errors (in text box) that I want to supplement with user form labels that act as hyperlinks that users can click to

相关标签:
2条回答
  • 2020-12-20 03:38

    The MSForms.Label object is going out of scope as soon as PlaceLinkLabel exits, as does the UserFormLabelLinks object reference; thus you're creating a label, but it's a fire-and-forget thing that you can't programmatically access as soon as End Sub is reached, hence the events never fire.

    You need a private field to hold on to the UserFormLabelLinks object reference (and thus keep the MSForms.Label reference around via the encapsulated pLabel field):

    Option Explicit
    Private clsLabel As UserFormLabelLinks
    

    Then remove this line in the procedure:

    Dim clsLabel As UserFormLabelLinks
    

    In other words, promote that local variable to a field, to keep it around after the procedure has completed.

    0 讨论(0)
  • 2020-12-20 03:47

    Another approach that worked:

    Placing Private pLabels As Collection atop the module where PlaceLinkLabel is stored

    and using

    If pLabels Is Nothing Then Set pLabels = New Collection
    pLabels.Add clsLabel
    

    at the end of PlaceLinkLabel module

    0 讨论(0)
提交回复
热议问题