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
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.
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