473,473 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to create check boxes in a menu and have them toggle?

2 New Member
Hi, I was wondering if anyone knows how to create check boxes in a menu and have them toggle in VBA (Access 2003). Another option is to use a comboBox but I think this looks bad and a dropdown menu would look better.

I have tried using the .FaceID and selecting a blank for one and a check for the other. In .onAction subroutine, I tried to access the FaceID and just switch the two (so the selected item has the check and the other one blank image) but I can't figure out how to set the control to the menu item and access these faceID's to be able to change them. I would post code but it is dead wrong, and I am sure there is a better way to do this but dont know how. Please help!
Nov 19 '10 #1
3 4376
ADezii
8,834 Recognized Expert Expert
Ironically, you Check/Uncheck Menu Items by manipulating their 'State' Property of the CommandBarControl Object. The following will illustrate this point:
  1. Set a Reference to the Microsoft Office XX.X Object Library.
  2. Execute the following Code will will create a New Weekdays Menu as the last Menu on your Main Menu. This Drop Down Menu will list the Days of the Week.
    Expand|Select|Wrap|Line Numbers
    1. Dim cbp As CommandBarPopup
    2. Dim varWeekDays As Variant
    3. Dim intCtr As Integer
    4.  
    5. 'Create an Array of Weekdays
    6. varWeekDays = Array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
    7.  
    8. 'Create the Top Level Menu
    9. Set cbp = CommandBars("Menu Bar").Controls.Add(msoControlPopup, Temporary:=True)
    10. cbp.Caption = "&Weekdays"
    11.  
    12. With cbp.CommandBar.Controls
    13.   For intCtr = LBound(varWeekDays) To UBound(varWeekDays)
    14.     With .Add(msoControlButton)
    15.       .Caption = varWeekDays(intCtr)
    16.       .OnAction = "fProcessWeekdays"
    17.     End With
    18.   Next intCtr
    19. End With
  3. Clicking on any given Day will place a Check Mark next to that Day, and clears the Mark for all other Days. This is handled by the OnAction Property of each Menu Option which calls the fProcessWeekdays() Function when a Menu Option is clicked. See Code Reference below:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fProcessWeekdays()
    2. Dim strCaption As String
    3. Dim cbc As CommandBarControl
    4. Dim cbcItem As CommandBarControl
    5.  
    6. 'Store the Caption of the Active Control
    7. Set cbc = CommandBars.ActionControl
    8. strCaption = cbc.Caption
    9.  
    10. 'Loop through all Controls in the CommandBar Object that is
    11. 'the Parent of the Selected Control
    12. For Each cbcItem In cbc.Parent.Controls
    13.   With cbcItem
    14.     'Check the Selected Item, Uncheck all the rest
    15.     If .Caption = cbc.Caption Then
    16.       cbcItem.State = msoButtonDown
    17.     Else
    18.       cbcItem.State = msoButtonUp
    19.     End If
    20.   End With
    21. Next
    22. End Function
  4. To arbitrarilly Check/Uncheck specific Menu Options in the Weekdays Menu (long...... syntax):
    Expand|Select|Wrap|Line Numbers
    1. 'Check Monday, Thursday, and Saturday
    2. CommandBars("Menu Bar").Controls("&Weekdays").CommandBar.Controls("Monday").State = msoButtonDown
    3. CommandBars("Menu Bar").Controls("&Weekdays").CommandBar.Controls("Thursday").State = msoButtonDown
    4. CommandBars("Menu Bar").Controls("&Weekdays").CommandBar.Controls("Saturday").State = msoButtonDown
    5.  
    6. 'Uncheck Monday, Thursday, and Saturday
    7. 'CommandBars("Menu Bar").Controls("&Weekdays").CommandBar.Controls("Monday").State = msoButtonUp
    8. 'CommandBars("Menu Bar").Controls("&Weekdays").CommandBar.Controls("Thursday").State = msoButtonUp
    9. 'CommandBars("Menu Bar").Controls("&Weekdays").CommandBar.Controls("Saturday").State = msoButtonUp
  5. I do realize that this is an awful lot to absorb, so simply download the Demo Attachment that I have created for you.
Attached Files
File Type: zip CommandBar.zip (17.4 KB, 241 views)
Nov 20 '10 #2
Kylee Lothrop
2 New Member
Awesome! This is exactly what I was looking for.
Thank-you!
Nov 22 '10 #3
ADezii
8,834 Recognized Expert Expert
You are quite welcome.
Nov 22 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Patrick L. Nolan | last post by:
We have a Tkinter application which has a menubar with cascade submenus. I would like to start the program with one of the submenu items state=DISABLED, then change it to state=NORMAL at a later...
2
by: hzgt9b | last post by:
Using VS .NET 2003, VB: I want to assign two different menu items the same shortcut, having only one enabled at a time... is this possible? In the forms designer, I have assigned both menu items...
9
by: DFS | last post by:
Anyone written any code to work with the CommandBar object? I have a custom menubar, with 6 buttons, and up to 3 levels of nested menus, such as: File File | Print (that's 2 levels)
0
by: Thomas Anderson | last post by:
I use the following code to create and destroy some menu items on the fly. Everything seems to work well, except that the new items are always last (after Help). Is there anyway to reorder this...
7
by: cefrancke | last post by:
I cant seem to find a straight answer on the following. I want to programmatically hide all menus except a basic custom report menu (during report preview) and right click pop-up A-Z sorting on...
0
by: Noulouk | last post by:
Hi, I build an add-in for Visual Studio 2005. I use the wizzard, I fixed the bug with envdte reference and build my project immediately after the wizzard. All seems to work, the add-in is shown...
14
by: Bryan | last post by:
I am attempting to make a web page more Netscape friendly... <a href="http:www.gordonceilings.com"></a> I have already corrected the table issues in an offline staging site (where I do the...
5
by: Jonathan | last post by:
Hello All, I am in the process of creating a 2/3 level collapsible/exspanible menu (called "nav") where users can click on a category and have the submenus appear beneath it and so on (allow...
1
by: swiftouch | last post by:
I'm getting an error message in FF2.0: document.getElementById(toggle) has no properties The goal of the script is, when I hover my mouse over an image, to make one div element visible while...
0
by: ARC | last post by:
Hello all, In access 2007, it appears you cannot put a toggle button underneath a menu id and have it show a Pressed / Not Pressed status. If you make the toggleButton ID as part of the main...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.