PDA

View Full Version : [SOLVED:] Macros for Menu Bar creation



bassman71
02-08-2007, 03:03 AM
Hello,
I've recently been assigned to tinker under the hood of an existing Access 2003 db. This db is layered with macros that call other macros within a complex set of Add Menus/Run Macros/sub routines that makes my brain cry uncle.

Being an Excel guy, I've created menu item classes as .xla enhancements and this seems like a more robust and ultimately simpler solution, especially when it comes to debugging. Furthermore, I've always read to keep clear of macro usage in Access.

My question: Is there a better way to create menu items in Access?

Thanks much..........bassman

Oorang
02-08-2007, 07:07 AM
Well some people prefer to build in the menus manually. But I prefer to build mine programatically. You can use the same methods in access or Excel, just make sure you have a reference set to the Office Library:

Sub MakeABar()
Dim cb As Office.CommandBar
Dim cbb As Office.CommandBarButton
Set cb = Access.CommandBars.Add("DeleteMe", msoBarTop, False, True)
Set cbb = cb.Controls.Add(msoControlButton)
cbb.Caption = "I Do Very Little"
cbb.FaceId = 12
cbb.Style = msoButtonIconAndWrapCaption
cbb.OnAction = "BarAction"
cb.Visible = True
End Sub

Sub BarAction()
MsgBox "I do nothing at all.", vbMsgBoxSetForeground
End Sub

bassman71
02-08-2007, 07:55 AM
Very nice thank you!