Consulting

Results 1 to 5 of 5

Thread: Calling VBA Subroutine from a switchboard

  1. #1
    VBAX Regular
    Joined
    Jun 2010
    Posts
    10
    Location

    Calling VBA Subroutine from a switchboard

    I am attempting to call a subroutine I have created, via a switchboard. I want to do this just begin to create a simplified menu that execute code I run frequently (like sync'ing external data to my tables, for example).

    I have created a switchboard entry for it that looks like this:
    http: //i69.photobucket.com/albums/i41/pklocke/switchboard.jpg
    (sorry...I guess I am too new to post a link...so merge the above back together with no spaces)



    the "PrepareTicketFile()" entry is the name of my subroutine. But alas, when I click on it to execute it in the switchboard, I get an error, saying:

    "The object doesn't contain the Automation object 'PrepareTicketFile."

    Probably somethings superobvious...so don't laugh (note: using access 2007).

    thanks!

    pklocke

  2. #2
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    Your Sub has to be module or class level to be called from the switchboard. All code written in Form modules is private to that Form.
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  3. #3
    VBAX Regular
    Joined
    Jun 2010
    Posts
    10
    Location
    Thanks...the code is in a module, thus why I thought it would work. What I did figure out, tho, was that if I changed the subroutine to a function, instead (I am not returning anything), then it worked fine.

    I am not up on "classes" at this point, so not sure what that is all about...but trying to learn.

    So, I guess I got it working...but perhaps not in the best of ways.

  4. #4
    VBAX Expert Imdabaum's Avatar
    Joined
    Jun 2006
    Posts
    652
    Location
    Quote Originally Posted by pklocke
    Thanks...the code is in a module, thus why I thought it would work. What I did figure out, tho, was that if I changed the subroutine to a function, instead (I am not returning anything), then it worked fine.

    I am not up on "classes" at this point, so not sure what that is all about...but trying to learn.

    So, I guess I got it working...but perhaps not in the best of ways.
    All it means is you cannot call a subroutine from Form1, when you are in Form2, Form3, etc... Subroutines only apply to the class/form that they are built under.

    If you have functionality that is used in Multiple forms, then you create a public function in a module. Functions can usually be accessed accross all classes/forms, queries and other modules provided they are declared public and not private.

    Long story short, if you want the subroutine to run in your switchboard, you need to put it in the switchboard directly, or use a function(not subroutine) as you discovered.
    Someday I'll understand everything...
    Even then...I'll still pretend I'm a beginner.

  5. #5
    VBAX Regular
    Joined
    Jun 2010
    Posts
    10
    Location
    Makes sense...(now LOL).

    Appreciate the help!

    Pat

Posting Permissions

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