Add items to a multi-column List Box

2019-08-05 04:43发布

问题:

Can someone please give me a simple example of how to add values to a multi-column listbox in vbscript. For example I have 4 columns and I'd like to add a row.

http://msdn.microsoft.com/en-us/library/office/ff869962%28v=office.15%29.aspx I tried this example but it kept telling me that it could not find the member .List.

I am using vbscript in MS Access. I have a form with a listbox. I want to populate this listbox with the textbox values I have such that when I click on Add, the values in the textboxes are added to the listbox under their particular column.

I have been searching to no avail - I haven't found one example that works or at least am I missing some import?

回答1:

I remember I have done this once and came to this solution:

Private Sub test()
    Me.lboTest.RowSourceType = "Value List"
    Me.lboTest.BoundColumn = 1
    Me.lboTest.ColumnCount = 2
    Me.lboTest.RowSource = "0;red;1;green;2;yellow;3;blue"
End Sub

Assemble the string beforehand with ; (or read it and append values, then write it back).
I don't know if there is any other way.

Btw., just to make sure you get this right: VBA and VBScript are different things. If you write this code within Access itself, you are using VBA, not VBScript.