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!
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: - Set a Reference to the Microsoft Office XX.X Object Library.
- 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.
- Dim cbp As CommandBarPopup
-
Dim varWeekDays As Variant
-
Dim intCtr As Integer
-
-
'Create an Array of Weekdays
-
varWeekDays = Array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
-
-
'Create the Top Level Menu
-
Set cbp = CommandBars("Menu Bar").Controls.Add(msoControlPopup, Temporary:=True)
-
cbp.Caption = "&Weekdays"
-
-
With cbp.CommandBar.Controls
-
For intCtr = LBound(varWeekDays) To UBound(varWeekDays)
-
With .Add(msoControlButton)
-
.Caption = varWeekDays(intCtr)
-
.OnAction = "fProcessWeekdays"
-
End With
-
Next intCtr
-
End With
- 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:
- Public Function fProcessWeekdays()
-
Dim strCaption As String
-
Dim cbc As CommandBarControl
-
Dim cbcItem As CommandBarControl
-
-
'Store the Caption of the Active Control
-
Set cbc = CommandBars.ActionControl
-
strCaption = cbc.Caption
-
-
'Loop through all Controls in the CommandBar Object that is
-
'the Parent of the Selected Control
-
For Each cbcItem In cbc.Parent.Controls
-
With cbcItem
-
'Check the Selected Item, Uncheck all the rest
-
If .Caption = cbc.Caption Then
-
cbcItem.State = msoButtonDown
-
Else
-
cbcItem.State = msoButtonUp
-
End If
-
End With
-
Next
-
End Function
- To arbitrarilly Check/Uncheck specific Menu Options in the Weekdays Menu (long...... syntax):
- 'Check Monday, Thursday, and Saturday
-
CommandBars("Menu Bar").Controls("&Weekdays").CommandBar.Controls("Monday").State = msoButtonDown
-
CommandBars("Menu Bar").Controls("&Weekdays").CommandBar.Controls("Thursday").State = msoButtonDown
-
CommandBars("Menu Bar").Controls("&Weekdays").CommandBar.Controls("Saturday").State = msoButtonDown
-
-
'Uncheck Monday, Thursday, and Saturday
-
'CommandBars("Menu Bar").Controls("&Weekdays").CommandBar.Controls("Monday").State = msoButtonUp
-
'CommandBars("Menu Bar").Controls("&Weekdays").CommandBar.Controls("Thursday").State = msoButtonUp
-
'CommandBars("Menu Bar").Controls("&Weekdays").CommandBar.Controls("Saturday").State = msoButtonUp
- I do realize that this is an awful lot to absorb, so simply download the Demo Attachment that I have created for you.
Awesome! This is exactly what I was looking for.
Thank-you!
ADezii 8,834
Recognized Expert Expert Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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)
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |