Multi-Select List Box

  • Thread starter Thread starter Kieran Hanley
  • Start date Start date
K

Kieran Hanley

Any help on this would be great.
I need to put a multi-select list box on a form. Max of 4
items in the box.
How do I save the selections to different fields in the
table. Such that Selection 1 is in Field1, Selection2 in
Filed2 Etc.
 
In the AfterUpdate event of the ListBox, you'll need to put VBA code to
determine which rows were selected, and assign them to the appropriate
fields.

Something along the lines of the following untested air-code:

Dim intLoop As Integer
Dim strField As String
Dim varItem As Variant

intLoop = 1
For Each varItem In Me.ListBoxName.ItemsSelected
If intLoop > 4 Then
Exit For
Else
strField = "Field" & intLoop
Me.Controls(strField) = Me.ListBoxName.ItemData(varItem)
intLoop = intLoop + 1
End If
Next varItem


Of course, the fact that you've got fields like Field1, Field2, ... implies
that your database hasn't been properly normalized. You may find it better
to store the selected values in a second "child" table of your main table.
 
Back
Top