Guides & Tutorials (beta)

What You Need to Know About CommandBar Control IDs

by Mike Palmatier Visual Basic 6 Created on 10/21/2005  |  Updated on 07/30/2024 0/5 ( 0 votes )

Each CommandBar control needs to have a unique ID so that you will know when a button or menu item has been pressed. There are many other things the ID is used for such as updating the control, searching for the control, and associating an icon with the control. The ID of the control is assigned when the control is added to the menu or toolbar.

If a toolbar item should perform the same function as a menu item, then the ID for both the menu item and toolbar button should be the same.

Valid IDs that can be used for CommandBar controls range from 100-9000. There are also some IDs which have a special meaning that is discussed in the Special Control IDs.

It is recommended that you declare a Constant value for your CommandBar IDs that that they can easily be identified throughout the code. We recommended that you follow some type of naming scheme. For example, for a menu item located in "File->New" you, would use an ID this: "ID_NEW_FILE" starting with the prefix ID, followed by the name of the menu item - all separated by underscores.

You can place the Constant ID values wither in a separate .bas file or in the "General" code section of the form the CommandBars control is located. You declare a Const when included as part of an object module, and a Public Const when in a .bas file.

Below is some sample CommandBar Control IDs that are declared in the "General" code section of a form.

Const ID_FILE_NEW   = 100
Const ID_FILE_OPEN  = 101
Const ID_FILE_CLOSE = 102
Const ID_FILE_SAVE  = 103
Const ID_FILE_EXIT  = 104

User Comments

No comments yet, sign in to comment.

Secure Transactions

Online transactions are secure and protected.


Ssl seal 1
This site is protected by Trustwave's Trusted Commerce program
CompliAssure Secured

Money Back Guarantee

If you are not 100% happy with your purchase within 30 days, you can return it for any reason. Your satisfaction is our priority!


Satisfication Guarantee

Contact sales@codejock.com for more details.