Search code examples
ms-accessvbapass-by-valuecall-by-value

VBA: passing by value to a property call


I have following code working.

Me.lbl1.Name

But I have a bunch of these labels, so how can I make the last line work?

Dim numberTry As Integer
numberTry = 1
Dim outputString As String
outputString = "lblCmd" & numberTry
Me.[outputString].Name

Any help or suggestion is greatly appreciated!!!


Solution

  • You can refer to a control by name if you use parentheses () and drop the dot.

    So:

    outputString = "lblCmd" & numberTry
    Me(outputString).Name