473,804 Members | 3,548 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding multiple values in a listbox to a table

22 New Member
Hi

I have a form with a few textboxes and some listboxes with multiple values allowed. I would like to use an append query to insert everything into a table but for some reason it just gives me no values at all for the listboxes (the textboxes are ok). Is there something that could be done.

Thanks in advance
Jan 17 '07 #1
4 2921
MMcCarthy
14,534 Recognized Expert Moderator MVP
Hi

I have a form with a few textboxes and some listboxes with multiple values allowed. I would like to use an append query to insert everything into a table but for some reason it just gives me no values at all for the listboxes (the textboxes are ok). Is there something that could be done.

Thanks in advance
To retrieve values from a multiselect listbox:

Expand|Select|Wrap|Line Numbers
  1. Dim valSelect As Variant
  2. Dim strValue As String ' just used for the demonstration
  3.  
  4.    For Each valSelect In Me.listboxName.ItemsSelected
  5.       strValue = strValue & ", '" & Me.listboxName.ItemData(valSelect) & "'"
  6.    Next valSelect
  7.  
  8.    ' to remove last comma
  9.    strValue = Left(strValue, Len(strValue)-2)
  10.  
Mary
Jan 18 '07 #2
NeoPa
32,579 Recognized Expert Moderator MVP
To retrieve values from a multiselect listbox:

Expand|Select|Wrap|Line Numbers
  1. Dim valSelect As Variant
  2. Dim strValue As String ' just used for the demonstration
  3.  
  4.    For Each valSelect In Me.listboxName.ItemsSelected
  5.       strValue = strValue & ", '" & Me.listboxName.ItemData(valSelect) & "'"
  6.    Next valSelect
  7.  
  8.    ' to remove last comma
  9.    strValue = Left(strValue, Len(strValue)-2)
  10.  
Mary
There's a small bug with this in that there are two common ways of stripping off the extra ',' and this mixes the two. It adds the extra comma at the front but strips it from the rear. I prefer the front way (oo er) because the code to strip it is shorter, but both ways work.
Expand|Select|Wrap|Line Numbers
  1. Dim valSelect As Variant
  2. Dim strValue As String ' just used for the demonstration
  3.  
  4.     For Each valSelect In Me.listboxName.ItemsSelected
  5.         strValue = strValue & ", '" & Me.listboxName.ItemData(valSelect) & "'"
  6.     Next valSelect
  7.  
  8.     ' to remove leading comma
  9.     strValue = Mid(strValue, 3)
Jan 18 '07 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
There's a small bug with this in that there are two common ways of stripping off the extra ',' and this mixes the two. It adds the extra comma at the front but strips it from the rear. I prefer the front way (oo er) because the code to strip it is shorter, but both ways work.
Expand|Select|Wrap|Line Numbers
  1. Dim valSelect As Variant
  2. Dim strValue As String ' just used for the demonstration
  3.  
  4.     For Each valSelect In Me.listboxName.ItemsSelected
  5.         strValue = strValue & ", '" & Me.listboxName.ItemData(valSelect) & "'"
  6.     Next valSelect
  7.  
  8.     ' to remove leading comma
  9.     strValue = Mid(strValue, 3)
Sorry that was my error, meant to place the comma at the end not the front. Good catch Ade.
Jan 18 '07 #4
MMcCarthy
14,534 Recognized Expert Moderator MVP
Revised code doing it my way ...


Expand|Select|Wrap|Line Numbers
  1. Dim valSelect As Variant
  2. Dim strValue As String ' just used for the demonstration
  3.  
  4.     For Each valSelect In Me.listboxName.ItemsSelected
  5.         strValue = strValue & "'" & Me.listboxName.ItemData(valSelect) & "', "
  6.     Next valSelect
  7.  
  8.     ' to remove leading comma
  9.     strValue = Left(strValue, Len(strValue)-2)
  10.  
Jan 18 '07 #5

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

Similar topics

2
1720
by: steve | last post by:
Hello, I am using ACCESS 2000 and am currently trying to make a database for a police department and they have several types of license classes. i.e A,B,C,D,E etc. What they have asked for is a drop down box with all the types listed and simple the ability to click on multiple check boxes to show what class(es) of license the person has. I have read through most of the articles on multiple list boxes but this is not my need. I dont need...
2
2736
by: DC Gringo | last post by:
I have two listboxes, the first of which is an autopostback=true that allows multiple row selection. When I select multiple values (by holding down CTL) in the first one, it should query the second one. I seem unable to do this as it only sends back the first item I select whether I have the CTL key down or not. Upon the return trip, I can select another one, but it still only sends value for the last one I selected. -- MY LISTBOX --...
2
1710
by: Ned Balzer | last post by:
Hi, Can anyone tell me what is the best approach for passing multiple keys from a listbox to a SQL update? I prefer to use stored procedures for updates. I am using asp.net 2.0 and SQL 2000, soon to upgrade to SQL 2005. I can envision several ways to do it, such as passing a delimited set of keys in a string to the sp, which then parses through them and maybe puts them into a temp table and performs the update. or is there maybe
3
2392
by: Jay Ruyle | last post by:
I'm trying to figure out a way to list several items in a listbox and let the user select any number of items in the listbox. I have tried to code in the items as bitwise items but all it stores in the database is the top item in the listbox. How can I get the listbox to add all the bit values to be stored and also come out properly when viewed later? Example:
0
1855
by: EricLondaits | last post by:
Hi, I have an ASP.NET page with a ListBox that is data bound to a table with a single field (it holds a list of valid IDs). The page also has a textBox into which you can add new valid IDs, one per line (this is in order to make the process of adding new IDs easy, since it's only done at time of configuration). I have no problem with retrieving the contents of the textBox, splitting it into a string array, validating the individual...
6
4165
by: Pippen | last post by:
Hi, I'm trying to read all the selected items in a ListBox. So after the user selects the values they want in the ListBox they select a button. This is where I want to put into a string all the values that were selected. The ListBox is populated by a stored proc that reads a DB table. Yes, I have the SelectionMode property set to MultiExtended, I have also tried MultiSimple. I have seen some examples for ASP Web forms but I'm using...
2
5149
by: billa856 | last post by:
Hi, My Project is in MS Access. In that I have one form in which I have some textboxes,comboboxes and listboxes. Now when I select value from 1st combobox(CustomerID) then it wil generate list for 1st listbox(PalletNo). Now I want to select miltiple values from that 1st listbox(PalletNo). and based upon this selection from 1st listbox(PalletNo) and combobox(CustomerID) I want to generate list for 2nd listbox(PONo). For example ...
2
6952
by: 6afraidbecause789 | last post by:
Hi - Has anyone ever used toggle buttons to select items in a listbox? I'd like to put about 24 toggle buttons on an unbound form that select or deselect items in a multiple select listbox. I've come across a way to set the listbox value to only 1 at a time, but need multiple toggle buttons to be on their corresponding listbox item values to be selected. Thanks!
2
12096
AccessIdiot
by: AccessIdiot | last post by:
Apologies if this has been answered before - I searched but couldn't find anything. I have a listbox that is populated with a query. I need to enable the user to select multiple items (simply set listbox Multi Select property to Simple yes?) and then I'd like to commit the choices to a single text field in a table, concatenated and separated by commas. So in other words if the listbox has these values: BRN CM XD RG
1
10317
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9143
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
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 we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.