473,387 Members | 1,745 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,387 software developers and data experts.

When to New Record to Junction Table

Hi,

I need a recommendation when to add a record to a junction table that
complements a many to many relationship. There will be a Contacts
form, and an Interests subform with the parent/child field being the
ContactID.

Table 1 - Contacts (ContactID (PK), First, Last, so on)
Table 2 - ContactsInterests (ContactInterestsID (PK), ContactID (FK),
InterestsID (FK))
Table 3 - Interests (InterestsID (PK), Interests_Description)

If I add a record to the junction table immediately after a new
contact is added, an update query will need to be run when values
change in the Interests subform. If the User selects an existing
Contact from a combo box, an 'Add Interests' button could be made
visible if no records exist in the juction table for that ContactID.
An append query would be run with the current ContactID. I am unsure
which is a better approach, or if this is the wrong approach
altogether.

Any help or recommendations you can make would be appreciated.

Henry

Dec 23 '07 #1
2 2211
The simplest idea is just to provide a combo in the subform for InterestID.
The user adds a new interest by selecting one in the combo, and can then add
another one on the next row of the (continuous?) subform.

If you have some interests that apply to almost everyone, you may perhaps
want to use the AfterInsert event procedure of the main form to insert that
interest into the junction table. For example, if you had a Yes/No field
named IsDefault in the junction table. This kind of thing:

Private Sub Form_AfterInsert()
Dim strSql as String
strSql = "INSERT INTO ContactsInterests (ContactID, InterestsID)
SELECT " & Me.ContactID & " AS ContactID, InterestsID FROM Interests WHERE
IsDefault = True;"
With dbEngine(0)(0)
.Execute strSql, dbFailOnError
If .RecordAffected 0 Then
Me.Sub1.Form.Requery
End If
End With
End Sub

The AddInterests button seems superfluous. If you want one on the main form,
you could toggle its Visible property in the main form's Current and
AfterInsert events, and the subform's AfterInsert and AfterDelConfirm
events.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Henry Stockbridge" <hs***********@hotmail.comwrote in message
news:6c**********************************@d21g2000 prf.googlegroups.com...
>
I need a recommendation when to add a record to a junction table that
complements a many to many relationship. There will be a Contacts
form, and an Interests subform with the parent/child field being the
ContactID.

Table 1 - Contacts (ContactID (PK), First, Last, so on)
Table 2 - ContactsInterests (ContactInterestsID (PK), ContactID (FK),
InterestsID (FK))
Table 3 - Interests (InterestsID (PK), Interests_Description)

If I add a record to the junction table immediately after a new
contact is added, an update query will need to be run when values
change in the Interests subform. If the User selects an existing
Contact from a combo box, an 'Add Interests' button could be made
visible if no records exist in the juction table for that ContactID.
An append query would be run with the current ContactID. I am unsure
which is a better approach, or if this is the wrong approach
altogether.

Any help or recommendations you can make would be appreciated.

Henry
Dec 23 '07 #2
On Dec 22, 7:16*pm, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
The simplest idea is just to provide a combo in the subform for InterestID..
The user adds a new interest by selecting one in the combo, and can then add
another one on the next row of the (continuous?) subform.

If you have some interests that apply to almost everyone, you may perhaps
want to use the AfterInsert event procedure of the main form to insert that
interest into the junction table. For example, if you had a Yes/No field
named IsDefault in the junction table. This kind of thing:

* * Private Sub Form_AfterInsert()
* * * * Dim strSql as String
* * * * strSql = "INSERT INTO ContactsInterests (ContactID, InterestsID)
SELECT " & Me.ContactID & " AS ContactID, InterestsID FROM Interests WHERE
IsDefault = True;"
* * * * With dbEngine(0)(0)
* * * * * * .Execute strSql, dbFailOnError
* * * * * * If .RecordAffected 0 Then
* * * * * * * * Me.Sub1.Form.Requery
* * * * * * End If
* * * * End With
* * End Sub

The AddInterests button seems superfluous. If you want one on the main form,
you could toggle its Visible property in the main form's Current and
AfterInsert events, and the subform's AfterInsert and AfterDelConfirm
events.

--
Allen Browne - Microsoft MVP. *Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Henry Stockbridge" <hstockbrid...@hotmail.comwrote in message

news:6c**********************************@d21g2000 prf.googlegroups.com...


I need a recommendation when to add a record to a junction table that
complements a many to many relationship. *There will be a Contacts
form, and an Interests subform with the parent/child field being the
ContactID.
Table 1 - Contacts *(ContactID (PK), First, Last, so on)
Table 2 - ContactsInterests (ContactInterestsID (PK), ContactID (FK),
InterestsID (FK))
Table 3 - Interests (InterestsID (PK), Interests_Description)
If I add a record to the junction table immediately after a new
contact is added, an update query will need to be run when values
change in the Interests subform. *If the User selects an existing
Contact from a combo box, an 'Add Interests' button could be made
visible if no records exist in the juction table for that ContactID.
An append query would be run with the current ContactID. *I am unsure
which is a better approach, or if this is the wrong approach
altogether.
Any help or recommendations you can make would be appreciated.
Henry- Hide quoted text -

- Show quoted text -
Many thanks.
Dec 23 '07 #3

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

Similar topics

1
by: mksql | last post by:
As an example, I am building an authentication mechanisim that will use data in the 3 left tables to determine rights to objects in a destination table, diagrammed below. In this structure,...
8
by: Marcy | last post by:
I am trying to build a database to keep track of training topics completed by people in my department. Our department has a set of 37 training topics. There are 7 job classifications in the...
1
by: que576 | last post by:
I have created a junction table so that I can relate data from 2 other tables. Table 1 - Category Table (has the following fields with data) CatID (primary key) CategoryName CategoryStatus ...
1
by: bg_ie | last post by:
I'm designing a database with 3 tables called Function, Test and Scene. A Function has multiple Tests, but a Test has only one Function. A many to many relationship exists between Test and Scene...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.