Possible? Refer to Sub using string?

elliotgr

Registered User.
Local time
Today, 11:02
Joined
Dec 30, 2010
Messages
67
I have a table containing the names of Subroutines and an Enabled field.
When i reference the table I want only the enabled subroutines to run.
Sample code out of my head:

Sub runEnabled_Routines

dimbd as database
dim rst as recordset
set db = currentdb
set rst = db.openrecordset("tbl_Enabled_Routines")
with rst
 
Why not use it in the openrecordset statement, as in..
Code:
SELECT subroutineName WHERE enabled=TRUE
This is a suggestion, as I have no clue what your table looks like..
 
Thanks
The issue is not to return the Sub name, but how to refer to it as a Sub to be executed, and not a string value.
One solution i thought of was to write code using code, but that is clumsy
 
I really do not understand your requirement.. Now that you have the list of Subs that are enabled just use Call and the string name to execute the sub.. Or if you want to check if a Sub is enabled before calling it use a DLookUp and if it is enabled run it else not.. something like..
Code:
If DLookUp("enabledField","subNameTbl","subName='theSubYouAreTryingToRun'")=True Then
Call theSubYouAreTryingToRun 
Else
Call MsgBox("Sorry not available", vbCritical)
End If
 
The only "interpret a line of code" in VBA that I can think of is Eval().

These types of functions in languages create their own virtual run-time environment, so for example in VBA there is no access to local variables or classes.

Give it a try, perhaps it is capable of going to a Sub name defined in a string.
 

Users who are viewing this thread

Back
Top Bottom