1

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?

Filburt
  • 17,626
  • 12
  • 64
  • 115
michelle
  • 2,759
  • 4
  • 31
  • 46
  • 1
    have you seen this [**tutorial**](http://vba4all.wordpress.com/category/vba-macros/two-column-listbox-userform-and-saving-results-to-spreadsheet/), specially `With ListBox1 .AddItem TextBox1.Value .List(.ListCount - 1, 1) = TextBox2.Value End With` –  Mar 14 '14 at 08:56
  • thanks I'll have a look – michelle Mar 14 '14 at 09:09

1 Answers1

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.

KekuSemau
  • 6,830
  • 4
  • 24
  • 34
  • I used your method, for some reason it is just showing me the numbers 0,1,2,3 and not showing me the 2nd column. any idea why? Also thanks for that - I was not aware Im afraid. – michelle Mar 14 '14 at 08:53
  • 1
    Yes, select the Listbox in the designer, go to the `Format` tab in the properties and set the `Column Widths`, e.g. to "0cm;10cm" - this would hide the first column. (I am using the German version, maybe you have to use `,`instead of `;` there...) – KekuSemau Mar 14 '14 at 08:55