Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Jan 2001
    Location
    Brecon, South Wales, UK
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using a variable to refer to a procedure (Access XP)

    I'm sure there must be an easy way of doing this. In an effort to make an application I am developing highly modular I have stored the names of a set of similar procedures in an Access table. The procedures themselves are stored in a Module. I want my code to retrieve from the table the name of the procedure to use and then issue a Call statement or similar, to invoke the procedure named in the table. How do I define a variable to hold the procedure name in such a way that I can invoke it or call it?

  2. #2
    Lounger
    Join Date
    Jan 2001
    Location
    Brecon, South Wales, UK
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using a variable to refer to a procedure (Access XP)

    Brilliant! Thanks

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Using a variable to refer to a procedure (Access XP)

    Use the Eval function for this. Your procedures *must* be functions for this to work.

    Example 1: The name of a function is stored in the variable strProcName. The function takes no arguments, and the value it returns is irrelevant (i.e., it acts like a procedure). Call it as follows:
    Eval strProcName & "()"

    Example 2: The name of a function is stored in the variable strProcName. The function takes an argument of type Long. The argument is stored in a variable lngArg. Call the function as follows:
    RetVal = Eval(strProcName & "(" & lngArg & ")")

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Using a variable to refer to a procedure (Access XP)

    This might work. Make sure all the procedures you want to call are functions. Let's say the fieldname in your table is called FunctionName. You could use DLookup or open a recordset to find the record you wanted. In the latter, you could then execute the function by doing this:
    Eval(rs!FunctionName)
    Note that the function name must include the parenthesis so Access knows this is a function; or add them above like this:
    Eval(rs!FunctionName & "()"
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •