Is there a way to call a specific routine using a variable?
For instance, my routine may be working varControl which may represent Control1, Control2 or Control3. After varControl is updated, I want to go on to the appropriate afterupdate routine (Control1_AfterUpdate, Control2_AfterUpdate...etc). Essentially, I need to call varControl & "_AfterUpdate"
I can't seem to trial-and-error this, nor could I find a thread on this topic.
I am not sure if this is what you mean, but you can write a private sub in the form module that takes a parameter when called, so you can determine where it was called from, and execute the relevant code (Select Case ?).
Then call the sub from the AfterUpdate even of all the required controls with the relevant parameter specified for that control.
I was about to suggest that you simply pass a parameter to the function.
Function Test(NameOfControl As String)
If NameOfControl = ___ Then
'(or case statement)
Call Test(me.activecontrol.name) 'unsure of this line
Call Tes(<write your control name here>) 'this might be simpler
Thanks MTB and georgev: that solution WILL work! I've got about 15 possible controls that the variable may represent, so the case statement won't be that bad.
Ideally, I was hoping to somehow directly call the appropriate sub with the sub name 'created' via concatenation of string variables. That would be cleaner and would avoid having to hard-code the control names.
But I'll take what works. Thanks for your time and ideas.
AfterUpdate is not really a sub or a method - it is an event procedure and is triggered by the event. Why do you need to fire it manually? Why not put the code in the appropriate event and therefore have it fire automatically when the event ocurs?
There is a way to "execute" a routine that is in a variable. You would do this with the Eval() function. For example, if you want to execute a function named "rptEmployees()", your code would look like:
Dim FunctionToRun as String
Dim ReturnVariable as Variant
FunctionToRun = "rptEmployees"
ReturnVariable = Eval(FunctionToRun)
This code will run the function named in the "FunctionToRun" variable and return the results in "ReturnVariable"
Hope this helps,
Thanks Pootle Flump! I had assumed it would be public but much better to state it up front. I did always talk about running a function, but again I did not state functions only. It really does not NEED to return a value, but it does need to be a function. Thanks!