Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Dec 2000
    Massachusetts, USA
    Thanked 0 Times in 0 Posts

    Executing a Subroutine (A97 SR2)

    I have created a Module with a Public Subroutine, but the only way I can find to run this is from the Design mode selecting Run.

    Is there a way to run this from a Macro or DoCmd? I would like it to be run from a menu selection.

    Also I would like to display a counter to the screen as the program runs (it cycles through records and I handle each individually and will increase the count after each record), but I'm not sure how to display this counter.


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Executing a Subroutine (A97 SR2)

    (1) To execute code from a macro, it must be a function, not a procedure. In Design mode of the macro, select the RunCode action and enter the function name followed by parentheses, e.g. MyFunc()

    (2) To execute code from a custom toolbar button or menu item, it must also be a function. In customize mode, right click the button or menu item, and enter one of the following in the OnAction box: either




    (3) You can call a subroutine from the code behind a form or report in two ways: either

    Call MySub()

    or just


    For instance, you can put a command button cmdMyButton on a form, and create an OnClick event handler that executes the subroutine:

    Private Sub cmdMyButton_Click()
    Call MySub()
    End Sub

Posting Permissions

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