By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,251 Members | 2,760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,251 IT Pros & Developers. It's quick & easy.

List Boxes - Storing Multiple values in a table

P: 2
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!
Jan 2 '07 #1
Share this Question
Share on Google+
4 Replies


ADezii
Expert 5K+
P: 8,627
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

Expand|Select|Wrap|Line Numbers
  1. Dim varItem As Variant, ctl As Control, strSports As String
  2. Set ctl = Me![lstBox]
  3. If ctl.ItemsSelected.Count > 0 Then
  4.   For Each varItem In ctl.ItemsSelected
  5.     strSports = strSports & ctl.ItemData(varItem) & ","
  6.   Next
  7.  
  8.   Me![txtSports] = Left$(strSports, Len(strSports) - 1)
  9. Else
End If
Jan 2 '07 #2

P: 2
Thank You so Much!!
Jan 3 '07 #3

ADezii
Expert 5K+
P: 8,627
Thank You so Much!!
The pleasure was all mine
Jan 4 '07 #4

P: 1
This is not making a lot of sense . Can you please elaborate. how to you use the command button. It does not have an after update event?
3 Weeks Ago #5

Post your reply

Sign in to post your reply or Sign up for a free account.