Results 1 to 7 of 7
  1. #1
    LOUIX is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2018
    Posts
    24

    Create a sub procedure for all forms

    Dear All,



    Attached you will see an example where a shortcut menu appears on right click on the form.
    The shortcut menu is called "test"

    I have more than 50 forms, but i cannot add this shortcut menu to the open events of all forms.

    Is there a way to create a general module or procedure so that i can refer to this general procedure/Module and call back the procedure when the forms are open.

    Please let me know if you need more information

    Attached a sample
    Thanking you in advance

    Ludovicrightclick.accdb

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    I have more than 50 forms, but i cannot add this shortcut menu to the open events of all forms.
    Why not? Is it just that you do not want to?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    You would have to touch each one to add the code to call the single procedure?

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    assuming you are using docmd.openform and the forms are not modal you could have code after the openform to populate the form open event with a call to a function in a standard module.

    your module code might be something like this (not tested) - note this is a public function

    Code:
    Public Function FormOnOpen(frm as Form)
    Dim NewMenu As Object
    
    
    On Error Resume Next
    wiith frm
        CommandBars("test").Delete
    
    
        Set NewMenu = CommandBars.Add("test", 5, False, True)
        NewMenu.Controls.Add 1, 10093, , , True
        NewMenu.Controls.Add 1, 19, , , True
        NewMenu.Controls.Add 1, 22, , , True
        NewMenu.Controls.Add 1, 499, , , True
        NewMenu.Controls.Add 1, 497, , , True
    
    
    end with
    
    
    End Sub
    and to use

    docmd.openform "myForm"
    FormOnOpen forms("myForm")


    Alternatively you could have code to open each form in turn in design view and add the following to the open event

    "=FormOnOpen([Form])"

    plenty of examples out there how to loop through the forms collection

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    Once the menu modification code is executed, it is available to all forms that have 'test' as the Shortcut Menu Bar property (and 'yes' as the Shortcut Menu property). Maybe that's already done for all the forms.
    If not, looping through the forms collection to modify a property was covered in a recent post here:
    Changing property on multiple forms (accessforums.net)
    Last edited by davegri; 01-23-2024 at 09:06 PM. Reason: simplify

  6. #6
    LOUIX is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2018
    Posts
    24
    Thanking you all, you help and assist me during this project. it worked now

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Quote Originally Posted by LOUIX View Post
    Thanking you all, you help and assist me during this project. it worked now
    So please explain how you solved it. It could help others, after all, that is what these forums are for?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 2
    Last Post: 11-27-2021, 08:33 AM
  2. Replies: 8
    Last Post: 09-20-2015, 11:00 AM
  3. Replies: 9
    Last Post: 08-10-2012, 03:10 AM
  4. create Procedure
    By rsl_mov in forum Programming
    Replies: 1
    Last Post: 08-07-2012, 10:40 AM
  5. Replies: 1
    Last Post: 11-17-2009, 06:55 AM

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