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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Menu Problem 1

Status
Not open for further replies.

Sameal

Programmer
Aug 6, 2001
142
US
In the Access help for menus it states that you can set up custom functions to run the tasks for each menu item. I am having a huge problem with this and quickly running out of time.

In the help files it does not say where the function code needs to be placed for the menu items. But it does however say to set the menu in the startup dialog form to make a global menu system, which I did.

Some wording in the file eludes to the fact that you could create a global module to house all your code, so I tried this by creating a module named 'modGlobal'.

I then placed my function code in this module, and set the Action property of the menu item to:

=MN_View_Sales()

This didn't work so I tried:

=modGlobal.MN_View_Sales()

This didn't work either so I tried:

=Modules!modGlobal.MN_View_Sales()

This didn't work either so I then created wrapper functions. I changed all the functions in modGlobal to sub-routines. Then in the startup form I defined functions for each of the menu items which simply called the sub-routines of my modGlobal module. This worked for a time, well not even much time really.

When I set my startup form !visible and moved it to the backgroup to call up a new form instantly my global menu system lost all functionality. Now it has begun to display the same error messages as before, stating that the call made by the menu item can not be found?

Does anyone have any clue what is up? Where do I put the code? How do I refer to the collection of Module objects? Help...please.
 
I think you mostly had it right in the first place. The menu VBA code must be in a standard module, and must have the Function (not Sub) header.

However, you need to set the global menu bar name in the Startup Properties (Tools|Startup menu), not the Start Form.

Your main problem is probably that there is a bug in Access 97 that often causes menu Action parameters that start with "=" to not be found, even though they exist. Microsoft's workaround is to remove the "=" and also the "()" at the end. And make sure you compile the menu code after every change. You may still very infrequently have a problem, but recompiling the whole project and restarting the database should fix it.

The Microsoft Knowledge Base has more information on this problem if you want it, but I remember it was hard to find it in KB. Rick Sprague
 
Thankyou, after reviewing what you said I went back in and tried it your way isntead of following the help files. While the help files explictly state that you should declare the menu item's action to be a function with the syntax: '=<functionname>()'

I found that you were correct. First of all I declared the menu routines as 'Sub' instead of function. In the action part of the menu item I listed just the name of the sub-routine, 'MN_View_Sales' and low and behold, it worked!

Thankyou so much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top