473,400 Members | 2,145 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,400 software developers and data experts.

populating a table from two listboxes

Hi
I got two tables, people and events. Each have a .name and a .ID.
In a third table, participation, I have a many to many connection
between the two, conection people to events.

In a form, I got two listboxes populated with the .name and the .ID
from the two tables.

I want to select multiple (or single) elements in both listboxes, and
then push a button to create new records in a the participations table
for each combination of events and people, thus adding the
participation of all the selected people to all the selected events.

Any thoughts much appreciated.
K
Nov 13 '05 #1
2 1485
create an unbound form with two listboxes, one for people, one for
events. both have 2 columns, the unique ID field for each
person/event, and the name of the person/event. column widths:0;1
column count: 2. Set both of the listboxes' multiselect property to
Extended. In the button to add records, add this code (or fix it up
nicer, even!)

Private Sub cmdAddParticipants_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim varPerson As Variant, varEvent As Variant
Dim ctlPerson As Control, ctlEvent As Control

Set ctlPerson = Me.mslbxPeople
Set ctlEvent = Me.mslbxEvents

Set db = CurrentDb

Set rs = db.OpenRecordset("tblEventParticipants", dbOpenTable,
dbAppendOnly)

For Each varPerson In ctlPerson.ItemsSelected
For Each varEvent In ctlEvent.ItemsSelected
rs.AddNew
rs.Fields("EmployeeID") = ctlPerson.ItemData(varPerson)
rs.Fields("EventID") = ctlEvent.ItemData(varEvent)
rs.Update
Next varEvent
Next varPerson

rs.Close
Set rs = Nothing
Set db = Nothing

MsgBox "done"
End Sub

I'm assuming you have these tables:
tblEventParticipants (ParticipantID, EventID)
tblEmployees (EmployeeID, FirstName, LastName,...)
tblEvents (EventID, EventName,...)
Nov 13 '05 #2
create an unbound form with two listboxes, one for people, one for
events. both have 2 columns, the unique ID field for each
person/event, and the name of the person/event. column widths:0;1
column count: 2. Set both of the listboxes' multiselect property to
Extended. In the button to add records, add this code (or fix it up
nicer, even!)

Private Sub cmdAddParticipants_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim varPerson As Variant, varEvent As Variant
Dim ctlPerson As Control, ctlEvent As Control

Set ctlPerson = Me.mslbxPeople
Set ctlEvent = Me.mslbxEvents

Set db = CurrentDb

Set rs = db.OpenRecordset("tblEventParticipants", dbOpenTable,
dbAppendOnly)

For Each varPerson In ctlPerson.ItemsSelected
For Each varEvent In ctlEvent.ItemsSelected
rs.AddNew
rs.Fields("EmployeeID") = ctlPerson.ItemData(varPerson)
rs.Fields("EventID") = ctlEvent.ItemData(varEvent)
rs.Update
Next varEvent
Next varPerson

rs.Close
Set rs = Nothing
Set db = Nothing

MsgBox "done"
End Sub

I'm assuming you have these tables:
tblEventParticipants (ParticipantID, EventID)
tblEmployees (EmployeeID, FirstName, LastName,...)
tblEvents (EventID, EventName,...)
Nov 13 '05 #3

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

Similar topics

2
by: Lamine Darbouche | last post by:
Can anybody help? I need to have three list boxes automatically populating each other, (ie when region is selected from the first listbox, it will populate automatically the second one which is...
8
by: buzz | last post by:
I would appreciate a pointer..... I have an asp page that links to an Access database and retrieves 2500 records and each record line has two listboxes. The problem is, although everything is...
1
by: Jimmy Tran | last post by:
Hi everyone, I have a form consisting of a combo box and two listboxes, they get their control source from a query. the whole form suppose to update a table. when i run the form, i pick an item...
4
by: bill yeager | last post by:
I have several template columns inside of a datagrid. Inside of these template columns are databound listboxes: <asp:TemplateColumn HeaderText="Crew Chiefs"> <ItemTemplate> <asp:listbox...
2
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,...
0
by: KBuser | last post by:
I'm building an internal site which will allow for extremely customizable queries to be run against our SQL Server (2000) DB. The page is done in ASP .net 2.0, with C# code behind. The initial...
4
by: rdemyan via AccessMonster.com | last post by:
I have to import building information from another system. I've decided to keep track of each set of data downloaded by including a Download_Date. That way I keep historical data. My table has...
0
by: koonda | last post by:
Hi all, I have a Project due after one week. It is a web service project. I have a Web Form which communicates to the web service and this web service communicates to the database. I have all my...
0
by: Anil Gupte | last post by:
I am having some issues with Listboxes Here is my code: Dim DSContent As New DataSet DSContent = L3GContent.GlobalDataSet URLListBox.BeginUpdate() For Each dr As DataRow In...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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.