I'm new to Microsoft Access and would like to create a ListBox (or ListView) with checkboxes, however I can't find any native way for doing so.
My intention is to display a list of values and have some of the values checked depending on what value is selected in a ComboBox on the form.
Please note that I'm needing such a control for a form and not a table (for which there's this "multivalued lookup field"). (Besides if there's a way to create a subform with a table with just the multivalue-column that reacts to what's selected in the ComboBox.)
An ordinary list box with the "Multi Select" property set to "Simple" doesn't display checkboxes.
I also can't see the "ListStyle" property described here.
Maybe it's somehow possible to display two columns in the ListBox of which the first is rendered as checkbox?
You can use the ListView
control. It is located under ActiveX Controls, the full name is Microsoft ListView Control, version 6.0
.
It has a separate set of properties: right-click -> ListViewCtrl object -> Properties, in there is the Checkboxes
property.
To fill the listview with data, see e.g. ACC: Sample Function to Fill a ListView Control
More info: Using the ListView Control
Edit
To comfortably work with the Listview object model, set a reference to Microsoft Windows Common Controls 6.0
= C:\Windows\SysWOW64\MSCOMCTL.OCX
on my Windows7 64bit.
Edit 2
I use a TreeView with checkboxes. Each Node
has a Checked
property, that checks or unchecks its checkbox. Where the Treeview has Nodes, the Listview has ListItems, but they have a Checked
property too.
Simplified code for Treeview (without hierarchies):
Dim oTree As TreeView
Dim oNode As Node
Dim RS As Recordset
Set oTree = Me.myTreeView.Object
oTree.Nodes.Clear
Set RS = DB.OpenRecordset("My query to fill the treeview")
Do While Not RS.EOF
Set oNode = oTree.Nodes.Add(key:=RS!foo, Text:=RS!bar)
oNode.Checked = (RS!someValue > 0)
RS.MoveNext
Loop
RS.Close
You can't modify a listbox of Access like that, but you can customize a subform in datasheet view to mimic such a listbox.
To display more or less fixed values, create a small local table to be bound by the form and fill it with the values you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With