Reputation: 5779
I am having an issue making a listbox into a multiselect listbox. I understand that the code to make a listbox multiselect is:
[forms]![formname]![listboxname].multiselect=2
However when I run this in Private Sub Form_Load() I get run-time error '2448' You can't assign a value to this object.
I guess I don't understand how to make a listbox multiselect, but I am pretty sure I understand how to use the multiselect listbox in VBA.
Any help on how to use the above code to actually change the listbox to multiselect would be appreciated.
Upvotes: 2
Views: 2233
Reputation: 1
I've found a way to set Multiselect Property via Vba Code:
DoCmd.SetWarnings = False
DoCmd.OpenForm myformname, acDesign
Forms(myformname).SetFocus
Forms(myformname).Controls(List3).MultiSelect = 0
DoCmd.Close acForm, myformname
DoCmd.SetWarnings = True
Upvotes: 0
Reputation: 1692
From Microsoft Office Help on property MultiSelect
:
This property can be set only in form Design view.
Set this property in Form Design, and don't try to change it in code.
Some examples of working with MultiSelect:
' Retrieve all selected values
Public Function ListBoxGetMultiSelect(ByVal rListBox As Access.ListBox) As String
Dim v As Variant
Dim vList As Variant
vList = ""
With rListBox
For Each v In .ItemsSelected
vList = vList & .Column(0, v) & vbCrLf
Next
End With
ListBoxGetMultiSelect = vList
End Function
' clear all selected values
Public Sub ListBoxClearSelection(ByVal rListBox As Access.ListBox)
Dim v As Variant
With rListBox
For Each v In .ItemsSelected
.Selected(v) = False
Next
.Value = Null
End With
End Sub
Upvotes: 5