Results 1 to 3 of 3
  1. #1
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051

    multiple buttons running the same on click

    Is there a way in access to run the same onclick event from multiple buttons (without copying and pasting the code for each new button)

    Something like


    private sub btn1,btn2,btn3 on_click()


    Do stuff

    end sub

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    two ways

    1. create a separate private sub in your form module e.g.

    private sub btnclickevent()
    ,your code here
    end sub

    then for each button, call the btnclickevent

    private sub btn1_click()
    btnclickevent btn1
    end sub


    2. create a separate public module e.g.

    public sub btnclickevent()
    ,your code here
    end sub

    then for each button properties, on the events tab, put

    =btnclickevent()

    where you would normally see [Event Procedure]

    which method is right for you depends on what the code does. If it is something that only relates to the current form, use method 1, if something to be used across a number of forms, use the second method

  3. #3
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Thx Ajax


    Sent from my iPhone using Tapatalk

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 10-09-2014, 11:37 AM
  2. Replies: 16
    Last Post: 02-13-2014, 05:26 PM
  3. Replies: 6
    Last Post: 12-04-2013, 07:00 PM
  4. Can't Click Any Buttons
    By netchie in forum Access
    Replies: 4
    Last Post: 05-08-2013, 10:38 AM
  5. Running a module from a button click
    By adacpt in forum Modules
    Replies: 4
    Last Post: 12-03-2012, 01:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums