VBA function call

Is there a way to call a function where the call is stored in a table

**Record 1  task            Function call**
124567      Email customer  Call function emailcus(a,b,c,d)
434535      AddCost         Call function addcost(a,b,c,d)

Greetings

Graham

+3
source share
2 answers

This is a variant of the answer already set by haarrrgh, so if you find this useful, be sure to transfer it as well.

There is another way to deal with placeholders in your functional calls stored in the database. First, modify the data like this:

**Record 1  task            Function call** 
124567      Email customer  Call function emailcus([TokenA],[TokenB])
434535      AddCost         Call function addcost([TokenA],[TokenB])

, [SquareBrackets] - , , . , tokens , ( ). , , , , ( , ).

, , :

Dim ReturnValue   As String    'or as appropriate for individual the function return
Dim EvalString    As String

EvalString = 'code to fetch from table

EvalString = Replace(EvalString, "[TokenA]", strValueA) 'strValueA passed in?
EvalString = Replace(EvalString, "[TokenB]", strValueB) 'strValueB passed in?

ReturnValue = Eval(EvalString)

VB6, ( , VBA), Replace , . , , , , SQL- ( Const, , ).

"" , , . Eval, , , . , , , , , , , Replace. , :

**Record 1  task            Function call** 
124567      Email customer  Call function emailcus('[TokenA]','[TokenB]')
434535      AddCost         Call function addcost('[TokenA]','[TokenB]')

Const. DB, :

**Record 1  task            Function call** 
124567      Email customer  Call function emailcus(""[TokenA]"",""[TokenB]"")
434535      AddCost         Call function addcost(""[TokenA]"",""[TokenB]"")

( Const...).

, , Replace:

EvalString = Replace(EvalString, "[TokenA]", """" & strValueA & """") 'strValueA passed in?
'or maybe
EvalString = Replace(EvalString, "[TokenB]", "'" & strValueB & "'") 'strValueA passed in?

: , Subs, Public , .

+3

, Eval().

:

Dim ReturnValue As String

ReturnValue = Eval("MyFunction(1, 2)")

, , .

, , a, b, c, d , VBA a, b, c, d .
Eval , , , - :

Dim ReturnValue As String
Dim EvalString As String

EvalString = "MyFunction(" & Variable1 & ", " & Variable2 & ")"

ReturnValue = Eval(EvalString )
+4
source

All Articles