473,772 Members | 3,786 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populating 1 listbox from another listbox

I have 2 list boxes on my form. I am trying to populate listbox B
with the selection from listbox A. I have set multi-select in both
boxes to Extended...

The user will select the items from listbox A and click an Add button
that will then copy the items to listbox B. Then for each item in B,
I need to add them to a database. If there are 3 items in listbox B,
I need to add 3 line items to table B...

Any ideas?
Jan 30 '08 #1
1 12883
On Jan 30, 1:09*pm, "dko...@gmail.c om" <dko...@gmail.c omwrote:
I have 2 list boxes on my form. *I am trying to populate listbox B
with the selection from listbox A. *I have set multi-select in both
boxes to Extended...

The user will select the items from listbox A and click an Add button
that will then copy the items to listbox B. *Then for each item in B,
I need to add them to a database. *If there are 3 items in listbox B,
I need to add 3 line items to table B...

Any ideas?
I have an idea; learn how to use Google.

This is straight off Microsoft's website:

Example
The following example uses the Selected property to move selected
items in the lstSource list box to the lstDestination list box. The
lstDestination list box's RowSourceType property is set to Value List
and the control's RowSource property is constructed from all the
selected items in the lstSource control. The lstSource list box's
MultiSelect property is set to Extended. The CopySelected( ) procedure
is called from the cmdCopyItem command button.

Private Sub cmdCopyItem_Cli ck()
CopySelected Me
End Sub

Public Sub CopySelected(By Ref frm As Form)

Dim ctlSource As Control
Dim ctlDest As Control
Dim strItems As String
Dim intCurrentRow As Integer

Set ctlSource = frm!lstSource
Set ctlDest = frm!lstDestinat ion

For intCurrentRow = 0 To ctlSource.ListC ount - 1
If ctlSource.Selec ted(intCurrentR ow) Then
strItems = strItems & ctlSource.Colum n(0, _
intCurrentRow) & ";"
End If
Next intCurrentRow

' Reset destination control's RowSource property.
ctlDest.RowSour ce = ""
ctlDest.RowSour ce = strItems

Set ctlSource = Nothing
Set ctlDest = Nothing

End Sub
Jan 30 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1353
by: Bill Brinkworth | last post by:
I want the user to type in part of a word, and I want to return all words from an Access word table that contains specified letters. If they were to type "fe??", it should return all words in the dictionary that are 4 letters and begin with "fe" into a listbox. I am having difficulting searching for all words and taking all those words and populating a listbox. Can you help? Here's what I have: CLASS - Public Property word() As String...
2
2914
by: collie | last post by:
Hi, I have 2 listboxes. The first gets populated from the db as soon as the page loads. The second listbox get populated based on the user's selection from the first listbox. However, currently the code is such that with each selection there is a postback. We want to avoid it using filter and javascript. I am not using ADO.NET but adodbc and no datagrids or datasets (please don't tell me that i should as my boss clearly doesn't want...
6
2879
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset a denormalized mirror of the database, but I'm not having much luck getting the selection logic down (I haven't found a 'hook' where I can access the listbox object as an object to set the listitem's selected property before it gets rendered).. ...
6
1580
by: P K | last post by:
I have a listbox which I am populating on the client (it contains a list of dates selected from calender). The listbox is a server control. When I get to the server after postback by selecting an item in the list, the list box cannot be accessed. How do I repopulate the listbox on the server after postback and be able to access the elements?
8
2549
by: jack-b | last post by:
Hi, I have a list box which displays countries names and a second listbox which displays their cites (based on the selection made in ListBox 1) If the user selects USA i want to display cities in the States - if the user selects multiple countries I want to display the cities in ALL the selected counties e.g. a user select US and England, the second list would display ally cities in England and all the cities in the US.
19
2997
by: hexagram | last post by:
Hi guys good day, can anybody help for my problem The Scenario is A Listbox (ID) - Multiple Select - everytime i choose in the list box the following outbound textbutton and subform will retrieve in my form- the folliwng value will get from another form i have a code but i need to customize it because everytime i choose ID in my list box my value in subform is multiplying by row i mean the value in subform is duplicating
5
2762
JustJim
by: JustJim | last post by:
Well this has been fun, but I now elect to "phone a friend" I have an Access application in which the operator can enter/choose the name of a training course and enter the number of teachers from a particular school who have attended that course. They can do this in four sets of combo box (for course name) and text box (number attended) and then move to the next record (another school's data) and do it all again. By looping through...
15
26694
by: NasirMunir | last post by:
I am trying to populate a listbox from another listbox on a access form. My first listbox has names of tables on a linked odbc databse. I am trying to display the tuples of the table in the second listbox based on the selection of table name in the first listbox I am new to VBA, and am trying to do that in the following manner: Private Sub List0_BeforeUpdate(Cancel As Integer) Dim strTable As String strTable = List0.Value ...
1
3512
by: TG | last post by:
Hi! I am using VB 2008 with SQL Server 2000 and SQL Server 2005 (depending which server the user selects to connect to). I have a listbox in which the user select the server to connect to. Another listbox that shows the databases in that particular server. Another listbox with the filesets from the selected database above.
0
9454
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
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, 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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10104
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9912
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
8934
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...
0
5354
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
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.