Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    run sub in module with OnClick (Access 2003, XP SP

    I have one named module with two subs and want to have these fire as needed on clicking on button A or B. RunCode in Macro only wants to see functions. Can't figure out just how to find and execute the specific sub in the module.

    TIA

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

    Re: run sub in module with OnClick (Access 2003, XP SP

    Why don't you create On Click event procedures instead of macros?

    If you prefer using a macro, is there an objection to changing the procedures (subs) to functions?

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: run sub in module with OnClick (Access 2003, X

    I already had the code written in a module and wanted to find a way to execute the code rather than copy-paste it into an event procedure. i don't have any objection to making the subs functions. i just didn't know if there was a way to branch out of a sub into another sub in Access - seem to recall trying this in the past and not getting it to work. Macros are not required - I am more interested in using the code I already have. Hope that makes sense...

    I infer from your response one way to go will be re-declare these subs as functions.

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

    Re: run sub in module with OnClick (Access 2003, X

    You can call a procedure (sub) from within an event procedure very easily. Let's say you have

    Sub Test()
    Beep
    End Sub

    In a standard module. By default, this is a public procedure, i.e. you can call it from anywhere in the database. Either use

    Call Test

    or even shorter

    Test

    For example:

    Private Sub cmdSomething_Click()
    Call Test
    End Sub

  5. #5
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: run sub in module with OnClick (Access 2003, X

    ok - thanks

Posting Permissions

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