Execute a function in vba where the function name is a variable

Posted on 2007-09-28
Last Modified: 2008-01-09

what i want to do is have a table that has the name of a function in one of the fields, i want some VBA code to read this table and load the list of function names, i think they will be strings at this point, then i want to call each of the functions in this list.

Getting the table and the list is not an issue so lest assume i have a recoed set and can loop over it, then i have the fields saved as a string so i have a string lets call it f_name, what i want to do is call or execute this function?

can this be done.
Question by:kplonk
    LVL 48

    Accepted Solution

    You can't do this directly, but a work around could be:

      Select Case f_name
        Case "Function1"
          Call Function1()
        Case "Function2"
          Call Function1()
        End Select


    Author Comment

    Ok thanks
    LVL 48

    Expert Comment

    by:Gustav Brock
    You are welcome.

    LVL 4

    Expert Comment

    From Microsoft Visual Basic Help:

    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

    Open in new window


    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    This article is a continuation or rather an extension from Cascading Combos ( and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
    Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now