Create Menu Bar with VBA

a_20120

tan
Local time
Today, 22:17
Joined
Nov 21, 2006
Messages
175
How can I create the Menu Bar with VBA?

when I click on any of the Menu Bar Options, open something like Form, Report, and etc...

Same as the Attached Menu Bar
 

Attachments

  • MenuBar.JPG
    MenuBar.JPG
    48.5 KB · Views: 6,423
How can I make my own menubar with VBA... Same as the attached file in the above thread
 
If I were you I'd read up on the CommandBars and the CommandBarControls collections in Access Help. Each of these collection have an Add() method you can use to create and return a reference to the object in question.
Here's a code fragment that might help get you started...
Code:
Function CreateMenuBar()
   Dim cb As Office.CommandBar
   Dim cbp As Office.CommandBarControl
   Dim cbc As Office.CommandBarControl
   
   'create the menu bar
   Set cb = CommandBars.Add("cmMainMenu", msoBarTop, True, True)
   With cb
      
      'create the "File" menu option
      Set cbp = .Controls.Add(msoControlPopup)
      With cbp
         .Caption = "&File"
         Set cbc = .CommandBar.Controls.Add(msoControlButton)
         With cbc
            .Caption = "Link to &CM data file..."
            .OnAction = "LinkToCMData"
            .FaceId = 1795
         End With
         Set cbc = .CommandBar.Controls.Add(msoControlButton)
         With cbc
            .Caption = "Link to &Bobs data file..."
            .OnAction = "LinkToBobsData"
            .FaceId = 1795
         End With
The scope of your question is significant and I don't have time for all the details, and there are many. Good luck and post back if you have more specific questions.
 
Hi Mr Lagbolt

I searched much and also tried ur code but i did not make my own menu bar.

if possible please make me same as the above attached menu bar
 
copy the functions i have created into a new module and save

then create this:

public function createmymenu()
call CreateMenu("MY Menu")
call AddMenuMainItem("MY Menu", "msoControlPopup","&Form")
call AddMenuMainItem("MY Menu", "msoControlPopup","&Settings")
call AddMenuMainItem("MY Menu", "msoControlPopup","&Backup")

Call AddMenuSubItem("MY Menu", "&Form", "msoControlButton", "Open Form1", 0, "=docmd.openform('frm1')")
Call AddMenuSubItem("MY Menu", "&Form", "msoControlButton", "Open Form2", 0, "=docmd.openform('frm2')")
Call AddMenuSubItem("MY Menu", "&Form", "msoControlButton", "Open Form3", 0, "=docmd.openform('frm3')")
Call AddMenuSubItem("MY Menu", "&Form", "msoControlButton", "Open Report1", 0, "=docmd.openreport('rep1')")
Call AddMenuSubItem("MY Menu", "&Form", "msoControlButton", "Open Report2", 0, "=docmd.openreport('rep2')")
End Function

and run it.

you should now have the menu you wanted.
 

Attachments

  • mymenu.JPG
    mymenu.JPG
    6.3 KB · Views: 2,952

Users who are viewing this thread

Back
Top Bottom