Referencing/going to a Label using Variable Text

  • Thread starter Thread starter LA Lawyer
  • Start date Start date
L

LA Lawyer

Happy New Year, all!

I want to direct the flow of a program using the value of a variable. How
is that done?
 
LA said:
I want to direct the flow of a program using the value of a variable. How
is that done?

It can't be done with a label name.

The most common alternative is to use Select Case to direct
the flow to a code block:

Select Case stringvariable
Case "label1"
'code block for label1
Case "label2"
'code block for label2
. . .
Case Else
MshBox "no code block for label " & stringvariable
End Select

A more elaborate and arguably more flexible way could be to
use the Run method or the Eval function

Sub something(...
. . .
Run stringvariable
. . .
End Sub

or

Sub something(...
. . .
Eval(stringvariable & "()")
. . .
End Sub

and put each code block in its own procedure

Public Function label1()
'code block for label1
End Function

Public Function label2()
'code block for label2
End Function
. . .
 
LA said:
Happy New Year, all!

I want to direct the flow of a program using the value of a variable.
How is that done?

I'm guessing you want to move to a field on a form using some sort of code.

If MyVariable = SomeValue then
Me.MyfieldName.SetFocus
else
Me.SomeOtherFieldName.SetFocus
End if

Else If could also be used but I would switch to a Select Case for more than
two values.
 
Your subject: line mentioned a "label" and "text", but the body of your post
asked about program flow.

Could you provide a bit more specific description of what you are trying to
do?

--

Regards

Jeff Boyce
Microsoft Access MVP

Disclaimer: This author may have received products and services mentioned in
this post. Mention and/or description of a product or service herein does
not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
Back
Top