Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macros to Construct Menu Items 1

Status
Not open for further replies.

Mantle51

Programmer
Aug 17, 2006
97
US
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 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..........Mick
 
I don't know of anyway to have a custom menu without using macros. Further, a macro must always call a function, not a sub.

I don't use macros at all, most of the time. My solution when I use cusotm menus is to still run all my logic in the code, just making anything that I would need to use in a menu into a function.

I keep my menus small.

Then I have a handful of macros that have one line each - "runcode". And then I run the necessary function.

The main problem with macros in Access is that if they have an error, you get a nasty "halt" pop-up - no nice little message box. So I try to make sure that the code in the macro will always run - and have anything more complex be handle elsewhere. My macros are only for opening forms and reports for that purpose. And even so, you have to make sure it's really debugged.

That may be why so many developers use command buttons and navigation screens instead of custom menus.
 
Here is an example how to use a sub on menubar.

In a module
Code:
Public Sub Message()
MsgBox "Hello there"
End Sub

then in the properties of the menu button

On Action= Message


Try to avoid Macros. They are pain in error handling.

________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
ZmrAbdulla ,

Thanks for the tip - I have tried that. I keep getting the message that my program can't find the macro I'm referring to. whether it's a function or a sub, whether I include parentheses or not, whether I include the equal sign or not, I can't get a custom menu to recognize anything except a macro. Is it specific to a version or something? I believe you know what you are talking about, but clearly I'm doing something different than you, because I can't get anything but a macro to work.
 
I am working in Access 2002. I don't think this will work only in that version

________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top