Ok...
I have a list box (called "lstbox" & unbound) that is populated by a table (tblsports). I need to be able to select multiple sports and then store it in a table called tblmaster (in column 24 the field is called "sports").
I know when you set the list box to simple or extended it returns a null value. I need this to return a string obivously. For example, if you like Tennis, Golf, and Hockey you can select it all and then store it in "sports" field of tblmaster
I have been looking at a bunch of tutorials and its been awhile since programming in college (C++ and VB).
Thanks in advance!
Multiple values should never be stored in a single Field but if you insist:
This Test code was placed on a Command Button on a Form, multiple values
were selected from the List Box [lstBox] and this code was executed in the
Button's Click() Event - it works fine.
1) Populate the List Box in whatever fashion you so desire
2) Set the Multi Select property of the List Box to Extended
3) Select 1 or more values from the List Box
4) Click on a Command Button, place the code in the AfterUpdate() Event of
the List Box, or wherever you like - its placement is irrelevant
5) A Comma Delimited list of selected Sports will be written to a "Hidden"
Text Box called txtSports which is bound to an appropriate Field in the Table
- Dim varItem As Variant, ctl As Control, strSports As String
-
Set ctl = Me![lstBox]
-
If ctl.ItemsSelected.Count > 0 Then
-
For Each varItem In ctl.ItemsSelected
-
strSports = strSports & ctl.ItemData(varItem) & ","
-
Next
-
-
Me![txtSports] = Left$(strSports, Len(strSports) - 1)
-
Else
End If