473,404 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Saving list box items as a string

15
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 10334
ADezii
8,834 Expert 8TB
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
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
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 Expert 8TB
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
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 Expert 8TB
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
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
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
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
by: incredible | last post by:
how to sort link list of string
1
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.