多选列表框问题
MultiSelect Listbox issues
我在将列表框转换为多选列表框时遇到问题。我知道制作列表框多选的代码是:
[forms]![formname]![listboxname].multiselect=2
然而,当我在 Private Sub Form_Load() 中 运行 this 时,我得到 运行-time error '2448' You can't assign a value to this object.
我想我不明白如何使列表框多选,但我很确定我了解如何在 VBA 中使用多选列表框。
任何有关如何使用上述代码实际将列表框更改为多选的帮助将不胜感激。
来自 属性 MultiSelect
上的 Microsoft Office 帮助:
This property can be set only in form Design view.
在表单设计中设置此 属性,不要尝试在代码中更改它。
使用 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
我找到了通过 Vba 代码设置多选 属性 的方法:
DoCmd.SetWarnings = False
DoCmd.OpenForm myformname, acDesign
Forms(myformname).SetFocus
Forms(myformname).Controls(List3).MultiSelect = 0
DoCmd.Close acForm, myformname
DoCmd.SetWarnings = True
我在将列表框转换为多选列表框时遇到问题。我知道制作列表框多选的代码是:
[forms]![formname]![listboxname].multiselect=2
然而,当我在 Private Sub Form_Load() 中 运行 this 时,我得到 运行-time error '2448' You can't assign a value to this object.
我想我不明白如何使列表框多选,但我很确定我了解如何在 VBA 中使用多选列表框。
任何有关如何使用上述代码实际将列表框更改为多选的帮助将不胜感激。
来自 属性 MultiSelect
上的 Microsoft Office 帮助:
This property can be set only in form Design view.
在表单设计中设置此 属性,不要尝试在代码中更改它。
使用 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
我找到了通过 Vba 代码设置多选 属性 的方法:
DoCmd.SetWarnings = False
DoCmd.OpenForm myformname, acDesign
Forms(myformname).SetFocus
Forms(myformname).Controls(List3).MultiSelect = 0
DoCmd.Close acForm, myformname
DoCmd.SetWarnings = True