Let's say I have a table of events: tblEvents
, and a table containing people: tblParticipants
. Many people can participate in an event, so we have a one-to-many relationship here, which is stored in a table: tblEvents_Participants
, which has records like this: Event_ID,Participant_ID
.
I would like to create a data entry form that in its first section has fields for input about the event, and in the second section, a continuous subform using tblParticipants
as a source, to which I can add people. Finally, I would like that when I click an cmdAddRecord
button, the following will happen:
- Add an event record to
tblEvents
, let's say:Event_ID = X
, based on inputs from section 1. - In the junction table,
tblEvents_Participants
, add the records:"X, participant1_ID", "X,participant2_ID"...
, based on the records chosen in the subform.
The problem I'm having is that such a thing supposedly requires 2 queries executed one after another: one to add the event record, and the other to add the records to the junction table, because the event's ID wouldn't exist
to use in the junction table before it is added to tblEvents
, and I haven't found a way to do this, at least without using VB code to execute queries one after another, which is pretty clumsy and hard to use.
EDIT: As per request, I'll post the data. I used pseudonyms in the post to make it as concise as possible, so I'll try to keep the data the same:
Comboxbox Row source:
SELECT tblParticipants.ID, tblParticipants.[FirstName], tblParticipants[LastName] FROM tblParticipants
Bound Column: 1
Column Count: 3
Column Width: 0,3,3
How the table looks inside the form (As I said, I used pseudonyms in my post so the field names are a bit different: (Every employee has many jobs, so employees==events, jobs == participants, ID refers to the junction table ID, it's irrelevant).
When I open the subform in a different tab, the entire table shows.
PS: Does the book record (ID=1, Title=Help) in your other post already exist before adding the authors?