Eval Function Example

The following example assumes that you have a series of 50 functions defined as A1, A2, and so on. This example uses the Eval function to call each function in the series.

Sub CallSeries()
    Dim intI As Integer

    For intI = 1 To 50
        Eval("A" & intI & "()")
    Next intI
End Sub

The next example triggers a Click event as if the user had clicked a button on a form. If the value of the button's OnClick property begins with an equal sign (=), signifying that it is the name of a function, the Eval function calls the function, which is equivalent to triggering the Click event. If the value doesn't begin with an equal sign, then the value must name a macro. The RunMacro method of the DoCmd object runs the named macro.

Dim ctl As Control, varTemp As Variant

Set ctl = Forms!Contacts!HelpButton
If (Left(ctl.OnClick, 1) = "=") Then
    varTemp = Eval(Mid(ctl.OnClick,2))
Else
    DoCmd.RunMacro ctl.OnClick
End If