ACC: How to Check a Menu Item Using Access BasicLast reviewed: June 8, 1997Article ID: Q90811 |
The information in this article applies to:
SUMMARYAdvanced: Requires expert coding, interoperability, and multiuser skills. Microsoft Access does not have any built-in macro or Access Basic commands you can use to place a check mark beside or remove a check mark from a menu command. To do this in Microsoft Access, you must use Access Basic code to call Microsoft Windows application programming interface (API) functions. NOTE: In Microsoft Access 7.0 and 97, you can use the SetMenuItem macro action to set the state of menu items (enabled or disabled, checked or cleared) on a custom menu bar or the global menu bar for the active window. For more information about the SetMenuItem action, search the Help Index for "SetMenuItem Action."
MORE INFORMATIONThe following Windows API function is used to check or clear a menu item. NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.
CheckMenuItem (ByVal hMenu As Integer, _
ByVal wIDCheckItem As Integer, _
ByVal wCheck As Integer) _
As Integer
This function places check marks next to or removes check marks from
menu items in the pop-up menu specified by the hMenu% parameter as
follows:
hMenu% Identifies the handle to the menu.
wIDCheckItem% Specifies the menu item to be checked.
wCheck% Specifies how to check the menu item. The
wCheck% parameter can be a combination of the
MF_CHECKED or MF_UNCHECKED with MF_BYPOSITION or
MF_BYCOMMAND flags. These flags can be combined
by using the bitwise OR operator. The values are
described as follows:
Value Meaning
----------------------------------------------------
MF_BYCOMMAND Specifies that the idCheckItem%
parameter gives the menu-item
identifier (MF_BYCOMMAND is the
default).
MF_BYPOSITION Specifies that the idCheckItem%
parameter gives the position of the
menu item (the first item is at
position zero).
MF_CHECKED Selects the item (adds check mark).
MF_UNCHECKED Clears the item (removes check mark).
Return Value The return value specifies the previous state of
the item. It is either MF_CHECKED or
MF_UNCHECKED. The return value is -1 if the menu
item does not exist.
NOTE: Top-level menu items (items on the Microsoft Access menu bar) cannot
have a check mark.
When determining the position of a menu command, separator bars count as commands. For example, to get to the Import menu command on the File menu in the Database window, use the arguments 0 (for the File menu) and 7 (for the Import command). Positions 3 and 6 correspond to the separator bars on the File menu.
ExampleThe example below creates a menu, associated with a form, that can be used to check or clear a menu command:
REFERENCESFor more information about custom menus, search for "customizing menus" using the Microsoft Access Help menu. For more information about similar programming features, please see the following articles in the Microsoft Knowledge Base:
ARTICLE-ID: Q88940 TITLE : How to Dim (Gray) Menu Items with Access Basic ARTICLE-ID: Q95935 TITLE : How to Determine Whether a Menu Item Is Checked |
Keywords : kbprg PgmApi
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |