Reputation: 71
There is probably a simple solution to this, but it is eluding me.
I have a textbox (name = CFMon), that references a month textbox. The user will submit values for all months, but they select a key month that is used for a calculation. I need to use their selected key month to get the value from the appropriate month textbox (each month is named mon1, mon2, etc)
When not using VBA, I would simply use the indirect function to evaluate all of the string.
test = Forms![Form]![CFMon] & ".value"
this does exactly what it is supposed to do and just regurgitate the text string
I am hoping the evaluate the reference and return the appropriate month value. For Example. The user selects CFMon = Mon3, the value will return the value the user inputs in the Mon3 (March) textbox
Upvotes: 1
Views: 313
Reputation: 16025
You could obtain the control from the Controls collection, e.g.:
test = Forms("Your Form Name").Controls(Forms![Form]![CFMon]).Value
Alternatively, you could use the eval
function, but I would advise against this:
test = eval("Forms![Your Form Name]![" & Forms![Form]![CFMon] & "].Value")
Upvotes: 4