As promised, I have constructed an example of using a common menu as a subform to multiple forms.
I originally tried to make the menu work in stand-alone mode as well as in embedded mode, but this proved more complex than I had anticipated. I got it working eventually, but I reverted to the more simple version for this example.
The principle here is that a single menu table is used for multiple forms (limited to 255). Each form contains a subform (sfShared) which contains the menu form (fShared). There is a main menu form (fMenu) which opens when you open the DB - this is used to open other forms which each have their own copy of the subform. In every case, the parent form name is used to select the relevant items from the menu.
The menu table contains control records, which are used for the internal workings. I have set two examples to show a static item (the main menu title) and a variable item (the last run date). These are identified with Form=0 in the table.
The menu itself is constructed in a Tab control, which has five tabs. Each tab contains six command buttons with associated labels. At run-time, only one tab is visible, with navigation between them achieved by the menu function (you'll see examples of this in the pages used).
I have allowed for user-code to be added in the module mMenus. You will see conditional compilation there, because I have two different ways to achieve the same result - it's a matter of personal preference.
I'm not going to explain the workings here - I have used comments to guide you through the process. If you encounter something which needs explanation, post your question here.
There is a query which might help you to see the menu table contents better. It has two parameters, [Form] and [Page].
There are some loose ends left for you to trip over - see if you can work out how the 'Close Form' menu action might work. Nothing happens in this version.
There are three 'hard' dependencies (that I remember). One is the need to run the fShared form within a subform control; next, is the naming convention for menu controls (commands and labels) in the menu pages (cmdppii and lblppii, where pp corresponds to the menu table mtPage field and ii to the mtItem field); the third is that each command (ctlppii) must be associated with its label (lblppii).
I have not included much error-checking, so you can expect failures - these will generally be data-dependent (i.e. the menu table content is unexpected). I would use a menu-builder form to manage the content to ensure valid relationships, but that's another project.
As this is a public post, the code is freely available to anyone who wants to use it. I ask merely that you let me know if you can improve the functionality and/or logic. Please acknowledge the source if you use or adapt the method.
Have fun!
