Variable in a Variable

CPGDeveloper

Board Regular
Joined
Oct 8, 2008
Messages
174
Hi All,

I don't know if this is possible, but I have a subroutine that populates the caption of a label. Something like this:

Forms!Form1!LabelTitle.Caption = titlevariable

'titlevariable' is defined by looking up the value in a table, and if the value in the table is a simple string, such as 'MANAGER', it works fine.

However, what if instead of passing the string 'MANAGER', I want to pass another variable.

So for example, if titlevariable = "anothervariable", which is also a variable. And anothervariable = "MANAGER"

In this scenario, is there a way I can write
Forms!Form1!LabelTitle.Caption = titlevariable, so that the caption of this label ends up being 'MANAGER' as opposed to 'another variable'?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Honestly I'm having trouble following what it is you're wanting to do. But let me take a guess...

Do you mean that a field in a table will have a value of anotherVariable in a record which also has a field containing the name of a function (anotherFunction, perhaps?) and you want to be able to reference anotherVariable and have it return the result of anotherFunction?
 
Upvote 0
I believe you understand -- let me see if I can be clearer: I have a table something like this

ID/Title
1/Manager
2/Developer
3/CEO
4/strAnalyst

Based on certain criteria, I look up the Title in the above table and assign it to a variable, say 'strTitle', and populate a label caption with said variable
Forms!Form1!LabelTitle.Caption = strTitle

In the first 3 options, all is good, the caption of the label will read the value in the title, 'Manager' or 'Developer' or 'CEO'.

In the fourth option, I don't want to the label to literally read 'strAnalyst'. I want it to read the value of the variable 'strAnalyst'.
 
Upvote 0
Very clear now, yes.

Can maybe be done. First, though, how are you deciding when to return the value in the field vs the value of the variable name in the field?
 
Upvote 0
Hi --

I don't have any particular criteria at the moment deciding that -- perhaps I should add a boolean field to the table to determine the usage --

ID/Title/IsVariable
1/Manager/False
2/CEO/False
3/Developer/False
4/strAnalyst/True
 
Upvote 0
Could be done with names.
Considering your strAnalyst text is in B5 of sheet 1

VBA Code:
Sub jec()
    Names.Add "strAnalyst", 100
    Sheets(1).Range("C2").Value = Evaluate(Sheets(1).Range("B5").Value)
End Sub
 
Upvote 0
Thanks JEC, however this is for an MS Access application, so I would be pulling 'strAnalyst' from a back end sql table
 
Upvote 0
I actually didn't notice it was an Access problem :LOL:
 
Upvote 0
If I understand the goal, I don't see how you can do this. You have to literally declare your variables at some point in your code so you cannot pull a variable name from a table and assign that to a declaration type. In other words, cannot write Dim DLookup("F1", "T1", "ID_T1 = 1") As String
You could Dim a variable and lookup a field value and assign the lookup value however. Maybe a code example would provide some clarification, but I cannot imagine why you'd want to do this anyway.
 
Upvote 0

Forum statistics

Threads
1,215,388
Messages
6,124,641
Members
449,177
Latest member
Sousanna Aristiadou

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top