Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2009
    Provided Answers: 15

    Unanswered: Building popup menus dynamically

    The database in the attached file (Popup_Menus.mdb) shows how to build contextual (popup) menus dynamically. Access 2003 had an interface to build such menus but it disappeared in Access 2007 and its successors.

    All menu items and their properties are stored into a table (Tbl_Menus) and each menu is built by calling the BuildMenus public sub wich calls the recursive function AddLevel() to actually build a menu and it's submenu(s), if any. BuildMenus takes 2 arguments: the name of the menu to be built and the name of a group in Tbl_Menus which represents the entry point (or top level menu).

    The example shows how to use this sytem to create the main menu of a hypothetical Sales and Invoicing application (see Frm_Menu in the database) but it can be used to build any popup menu. More than one menu can be built in an application by simply adding entries in the table Tbl_Menus.

    The structure of Tbl_Menus is as follows:
    Column Name |Data Type |Nullable  |Comments
    [Group]     | TEXT(50) | NOT NULL | Name of the Menu (or name of another Group) (1).
    [Type]      | INTEGER  | NOT NULL | Type of control (1 = button - 10 = submenu) (2).
    [Rank]      | INTEGER  | NOT NULL | Ordinal order of the item within the group.
    [Caption]   | TEXT(50) | NOT NULL | Caption of the menu control.
    [Function]  | TEXT(50) | NOT NULL | Function called to process the menu item (3).
    [Action]    | TEXT(50) | NULL     | Operation to be performed (4).
    [Arguments] | TEXT(50) | NULL     | Arguments to be used with [Action] (5).
    [ID]        | INTEGER  | NULL     | Unique identifier of the menu item (6).
    [Exclusive] | BIT      | NULL     | Close all other open Forms ans Reports when True.
    Note: You can call the public sub CreateMenuTable to create the table Tbl_Menus.

    (1) Can be any name.
    (2) 1 means the item is a menu command button, 10 means it's the entry to a submenu.
    Other values are possible but they are not handled in this example.
    (3) It can be the name of a public Function to be called when the item menu is
    activated (when [Type] = 1) or it can be the name of another group (when [Type] = 10).
    (4) The operations recognized and processed by the public function ExecMenu()
    are: "OpenForm", "OpenReport" and "Execute". Another function could implement more or different operations.
    (5) Parameters that will be used to call the action. Each parameter is separated
    from the others by a semi-colon ";" (see ExecMenu() code).

    For OpenForm and OpenReport actions:
       Index  | Meaning
          0   | Name of the Form or Report to be open.
          1   | Desired ViewMode (Text). Can be: "acViewDesign", "acViewFormDS", "acViewNormal", "acViewPreview".
          2   | Filter.
          3   | Window Mode (Text). Can be: "acDialog", "acHidden", "acIcon", "acWindowNormal".
          4   | Parameters passed to the object (OpenArgs).
    (6) Number that uniquely identifies the menu item. It's the primary key of the table.
    Attached Files Attached Files
    Have a nice day!

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    should this be added to the code bank?
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Mar 2009
    Provided Answers: 15

    If you consider it to be interesting enough, sure.
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts