VBA can't take reference of an object

2

I've got an array I need to populate with references to labels on a display. I've managed to reduce my issue to a MWE below:

Private Sub Button1_Released()
    Me.TestLabel.Caption = "Button1"
End Sub

Private Sub Button2_Released()
    Dim o As MSForms.Label
    Set o = Me.TestLabel
    o.Caption = "Button2"
End Sub

The code for button1 works while buttton2 fails with message, "Method Caption of object ILabelControl failed (0x80010105)".

TypeName(Me.TestLabel) returns "Label". When I change my Dim to "Label" instead of "MSForms.Label" I get behavior that looks like an uninitialized variable being accessed. For example: sometimes button2 will produce chinese characters in the label, often nothing happens but the VBA module will crash.

I have tried removing and restoring the typelib reference with no effect. I have tried changing the reference from the office v16 fm20.dll to the syswow64 v14 fm20.dll with no effect.

This is a previously functioning application developed on one machine and moved to another. I have considered recreating the displays, but the MWE comes from a new display, created on the new machine, with just a label and two buttons.

Pretty stuck here.

ed: changing the dim from MSForms.Label to Object worked

vba
asked on Stack Overflow Sep 27, 2017 by eric • edited Sep 29, 2017 by eric

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0