473,480 Members | 2268 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Saving list box items as a string

15 New Member
Is there anyway to save multiple items selected in a list box to a string? Is it then possible to save the string to a record field in a table? Or is there another way to capture multiple items selected and stored them in a table? For example: I have a list box with the following items:
Listbox
cat
dog
rabbit

Table name = Animal_tbl
Animal Selected - this is a column heading and a text field.
Dec 28 '10 #1
6 10343
ADezii
8,834 Recognized Expert Expert
Is there anyway to save multiple items selected in a list box to a string?
Yes there is but:
  1. What is your reason for storing multiple, selected Objects from a Multi-Select List Box to a Field in a Table?
  2. How do you wish the String to appear?
    Expand|Select|Wrap|Line Numbers
    1. cat,dog,rabbit
    2. cat dog rabbit
    3. cat-dog-rabbit
    4. etc...
Dec 29 '10 #2
MarkP
15 New Member
I'm trying to store multiple values in a field to reduce the amount of check boxes in a table. My present table has over 75 columns that are used to received check boxes from a form. But I need to capture each record/event from the user. So each record is unique and will be used in trending analysis. If there is another way that I can use to reduce the number of columns in a table then I will be open to that suggestion. Thank you and Happy New Year.
Dec 29 '10 #3
MarkP
15 New Member
Sorry about not answering your last question. I was hoping to store the string with comas like in your first example above.
Dec 29 '10 #4
ADezii
8,834 Recognized Expert Expert
Assuming your List Box is named lstAnimals:
Expand|Select|Wrap|Line Numbers
  1. Dim ctl As ListBox
  2. Dim varItm As Variant
  3. Dim strBuild As String      'To build Animal Selected List
  4.  
  5. Set ctl = Me![lstAnimals]
  6.  
  7. If ctl.ItemsSelected.Count < 1 Then Exit Sub
  8.  
  9. For Each varItm In ctl.ItemsSelected
  10.   strBuild = strBuild & ctl.ItemData(varItm) & ","
  11. Next varItm
  12.  
  13. strBuild = Left$(strBuild, Len(strBuild) - 1)
  14.  
  15. CurrentDb.Execute "INSERT INTO Animal_tbl ([Animal Selected]) VALUES " & _
  16.                   "('" & strBuild & "')", dbFailOnError
Sample Results:
Expand|Select|Wrap|Line Numbers
  1. Animal Selected
  2. Rabbit
  3. Cat,Lion
  4. Cat,Dog,Rabbit,Lion
  5. Cat,Dog,Rabbit,Mouse,Lion
  6. Dog
  7. Dog,Rabbit,Mouse
Dec 29 '10 #5
MarkP
15 New Member
Thank you for that. You should change your hobby (database programming) to the day job. But either way I'm glad you read my message.
Dec 29 '10 #6
ADezii
8,834 Recognized Expert Expert
Some things are fun as long as they are a hobby - once they become a job, then they are a burden! (LOL).
Dec 29 '10 #7

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

Similar topics

5
6811
by: Peter Collinson | last post by:
Hi... Is there any way to style a List Item a different color and size than the <LI> in an Ordered List? I'd like a red super-script number and a dark blue text in a page's footnotes. And...
2
3044
by: Unknown User | last post by:
How can I separate list items displayed inline by vertical bars | ? If I use a background image that simulate a vertical bar, and I put this bg image behind each list item, the last list item will...
2
5742
by: deepakp | last post by:
Hi, I'm trying to create a site index page. The page layout will consist of a header, left navigation and content display. The left navigation and content display should look like the image file...
9
4389
by: incredible | last post by:
how to sort link list of string
1
3166
by: RSH | last post by:
Hi, I have a situation where I need to add several "Hidden" properties to list items in a dropdownlist. By default the DropDownList item has two properties with regards to the listitems...
0
1679
by: John Dalberg | last post by:
using VS 2005. I have an unordered list with list items which are displayed horizontally. Some of the list items have hyper links and some have checkboxes. The problem is that the...
9
2777
by: shapper | last post by:
Hello, How can I filter a List(Of String)? I need to get the list elements which start with the letters contained in the variable Text. Thanks, Miguel
4
3019
by: Keith Hughitt | last post by:
For example, If you have a list: <ul> <li>item 1 is short.</li> <li>item 2 is a little bit longer</li> </ul> regardless of the size of the contents of each list item, the element
0
2048
by: c0mrade | last post by:
I have a problem with getting the list items, below is my hibernate code, after that code there is my method ..and below that is my junit test. How can I make sure that query is executing properly,...
16
10589
Frinavale
by: Frinavale | last post by:
What I'd like to do is take a list and display it's items in a circle. For example (the order of the in the circle doesn't matter..except for Item1, it has to be at the top): Item1 ...
0
7097
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3003
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2993
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
567
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.