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.

Solved: Macro Require Function Code

Discussion in 'Business Applications' started by mariaa33, Sep 29, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. mariaa33

    mariaa33 Thread Starter

    Joined:
    Aug 7, 2008
    Messages:
    164
    I created a macro to runcode for a sub procedure and included that as a button on the switchboard. It executes just fine from VBA but when I try to run the macro, the help says it has to use a Function to call the subprocedure. I do not know how to write a Function to call a subprocedure (ExportWeeklyChron). Can anybody help?
     
  2. MRdNk

    MRdNk

    Joined:
    Apr 7, 2007
    Messages:
    439
    I'm guessing this is Access.

    Just type your sub's name where it says Function - it works for me. I just wrote a simple

    Code:
    Sub aTest ()
    [INDENT]MsgBox "Hello World"[/INDENT]
    End Sub
    And where the switchboard item, under Command = Run Code, Function Name = aTest; and this works.

    If you've tried this and it doesn't work, then can you give some more information, what options are you selecting on the switchboard etc.
     
  3. mariaa33

    mariaa33 Thread Starter

    Joined:
    Aug 7, 2008
    Messages:
    164
    I did the exact code that you have above and I get "There was an error executing the command" from the switchboard. If I have the above as a macro to run code, I get "The expression you entered has a function name that Microsoft Access can't find." I am using Access 2003.
     
  4. mariaa33

    mariaa33 Thread Starter

    Joined:
    Aug 7, 2008
    Messages:
    164
    Nevermind, I changed the macro to just run the query and output to excel file with the Output To. Boy, much simplier!!
     
  5. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    The example above shows a sub procedure NOT a function.

    A function has the following syntax
    Code:
    Public Function MyFunction()
    'Your Code
    End Function
    Regards,
    Rollin
     
  6. MRdNk

    MRdNk

    Joined:
    Apr 7, 2007
    Messages:
    439
    Yes - I know this, however, it works.

    This is very odd, as I ran it both at Home and at Work, both Access 2003, and both work perfectly.
     
  7. Sponsor

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!

Loading...
Thread Status:
Not open for further replies.

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

  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