2

I have a combo box on a form that is linked to a SharePoint field, the combo box populates correctly however I am having difficulty trying to add VBA code to select all of the options or to unselect all options.

With a standard combo box you can use:

cmbBox1.value = ""

and that will reset the field. The same thing can be done with a list box that has multi-select enabled however this tosses an error, "This control is read-only and cannot be modified", with the combo box that has multi-select because of the lookup.

I have done some searching however no one seems to have a real answer other than to use a listbox instead and that isn't a solution here.

Has anyone worked with one of these fields and know how to select all of the options using VBA?

Here is a link describing this type of field but it does not discuss how to interact with it using VBA - http://office.microsoft.com/en-us/access-help/use-a-list-that-stores-multiple-values-HA010031117.aspx.

UPDATE:

There has been some confusion about the type of field I was describing so I have added some screen captures to show the difference between a combo box that allows multiselect, a list box that allows multiple options and a combo box with the option added.

First the field I was describing:

MultiSelect Combo Boc

Second the list box:

Listbox with multivalue enabled

Lastly the combobox:

Combobox with a Select All option

These images visualize the issue that was described. As you can see there are multiple check boxes that need to be selected or unselected. Normally I would not create a field like this but as described above this is how Access interprets a combobox from SharePoint that allows for multiple selections.

4

2 回答 2

3

经过大量的搜索和反复试验,我想通了。

要取消选中所有复选框,它是

cmbBox1.Value = Array()

因此,有了这些信息,我认为要选择它们必须在一个数组中的项目。使用组合框中的所有项目创建一个数组,然后将组合框设置为等于该数组将选择所有项目。

我使用了一个基本循环来设置数组的每个元素

Dim SelVals(), i
ReDim SelVals(0 to cmbBox1.ListCount - 1)
For i = 0 to cmbBox1.ListCount - 1
     SelVals(i) = cmbBox1.Column(1,i)
Next i
cmbBox1.Value = SelVals

显然,您不仅限于使用全部内容 - 您可以分配任何数组,这些将是选定的值。

于 2013-05-27T09:51:14.713 回答
0

http://msdn.microsoft.com/en-us/library/office/aa140084(v=office.10).aspx 我相信这涵盖了您的要求

于 2013-05-20T20:05:19.947 回答