1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Access VBA - Using Call Statement

Discussion in 'Business Applications' started by curtswanson, Mar 22, 2002.

Thread Status:
Not open for further replies.
  1. curtswanson

    curtswanson Thread Starter

    Jun 22, 2000
    When using the Call statement in Access VBA, is there a way to use a dynamic value for the Sub or Function name. For instance,

    Dim MyVariableFunction as String
    MyVariableFunction = "Func1"
    Call MyVariableFunction

    Where "Func1" is the name of a function. The above code obviously doesn't work. A string is not a valid argument for the Call statement, only a Sub or Function name is allowed.

    I want to run different subroutines based on the value of a variable. I prefer not to build an If..Then..Else or Select Case with all the possible values but that is what I'm facing unless someone can help.

  2. downwitchyobadself


    Oct 13, 2000
    There is indeed a hierarchy you can set to call specific procedures in specific modules.

    I've been programming in Access for over 5 years, I've never once used it.

    While it might sound practical, it is actually only useful if you are actually creating modules on the fly (if I understand your situation, you're not, you just want to call them on the fly), which you would be doing only in the rarest of cases.

    If you think about it, it's about the worst documenting situation you can think of. All good code--and I do mean all, and I do mean good--should be immediately readable to a competent developer, because you may some day be hit by a train, but your app needs to keep going. Procedure calls are not variables; variables are variables.

    I'd recommend doing the work to use if then or select case.
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/73518

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice