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
4 2906 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: -
Dim valSelect As Variant
-
Dim strValue As String ' just used for the demonstration
-
-
For Each valSelect In Me.listboxName.ItemsSelected
-
strValue = strValue & ", '" & Me.listboxName.ItemData(valSelect) & "'"
-
Next valSelect
-
-
' to remove last comma
-
strValue = Left(strValue, Len(strValue)-2)
-
Mary
NeoPa 32,558
Recognized Expert Moderator MVP
To retrieve values from a multiselect listbox: -
Dim valSelect As Variant
-
Dim strValue As String ' just used for the demonstration
-
-
For Each valSelect In Me.listboxName.ItemsSelected
-
strValue = strValue & ", '" & Me.listboxName.ItemData(valSelect) & "'"
-
Next valSelect
-
-
' to remove last comma
-
strValue = Left(strValue, Len(strValue)-2)
-
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. - Dim valSelect As Variant
-
Dim strValue As String ' just used for the demonstration
-
-
For Each valSelect In Me.listboxName.ItemsSelected
-
strValue = strValue & ", '" & Me.listboxName.ItemData(valSelect) & "'"
-
Next valSelect
-
-
' to remove leading comma
-
strValue = Mid(strValue, 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. - Dim valSelect As Variant
-
Dim strValue As String ' just used for the demonstration
-
-
For Each valSelect In Me.listboxName.ItemsSelected
-
strValue = strValue & ", '" & Me.listboxName.ItemData(valSelect) & "'"
-
Next valSelect
-
-
' to remove leading comma
-
strValue = Mid(strValue, 3)
Sorry that was my error, meant to place the comma at the end not the front. Good catch Ade.
MMcCarthy 14,534
Recognized Expert Moderator MVP
Revised code doing it my way ... -
Dim valSelect As Variant
-
Dim strValue As String ' just used for the demonstration
-
-
For Each valSelect In Me.listboxName.ItemsSelected
-
strValue = strValue & "'" & Me.listboxName.ItemData(valSelect) & "', "
-
Next valSelect
-
-
' to remove leading comma
-
strValue = Left(strValue, Len(strValue)-2)
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |