Answered
How do I insert record in DB ONLY if it does not already exist?
I'm using Microsoft Access and I have 3 tables: Jobs, KSAs,
and JobKSAs. JobKSAs is a linking table, i.e., it links the KSAs
that are relevant to a given job.
A KSA can be linked to more than one job, but it should be linked to a single job only once. (i.e., there's no reason why the KSA "communication skill" should be linked to the job "salesperson" more than once.)
Unfortunately, I discovered that I could link a KSA to a given job as many times as I wanted, i.e., a new record would be added to Table: JobKSAs.
The KSA-Job link is created (or edited) using a form in a file entitled "add_ksa.cfm".
Table: JobKSAs contains these fields:
JKID (the primary key for this table),
frn_JobID (the foreign key pertaining to the unique ID of the given Job), and,
frn_KSAID (the foreign key pertaining to the unique ID of the given KSA).
The form data is transmitted to "ksa_au_pro.cfm", which I hope will run a check to see if a record in JobKSAs with the given frn_JobID and frn_KSAID already exists. If such a record already exists, then I don't want a new record added to Table: JobKSAs. In addition, I want the user to be taken to "ksa_already_linked.cfm", which tells the user that the KSA has already been linked to the given Job.
If a record in Table: JobKSAs containing frn_JobID and frn_KSAID does not already exist, then I want it to be added to Table: JobKSAs, and for the user to be taken to "ksa_confirm.cfm", which tells the user that the KSA has been linked to the given job.
Below is my code for "ksa_au_pro.cfm".
Thank you for any help with this!
Luke
A KSA can be linked to more than one job, but it should be linked to a single job only once. (i.e., there's no reason why the KSA "communication skill" should be linked to the job "salesperson" more than once.)
Unfortunately, I discovered that I could link a KSA to a given job as many times as I wanted, i.e., a new record would be added to Table: JobKSAs.
The KSA-Job link is created (or edited) using a form in a file entitled "add_ksa.cfm".
Table: JobKSAs contains these fields:
JKID (the primary key for this table),
frn_JobID (the foreign key pertaining to the unique ID of the given Job), and,
frn_KSAID (the foreign key pertaining to the unique ID of the given KSA).
The form data is transmitted to "ksa_au_pro.cfm", which I hope will run a check to see if a record in JobKSAs with the given frn_JobID and frn_KSAID already exists. If such a record already exists, then I don't want a new record added to Table: JobKSAs. In addition, I want the user to be taken to "ksa_already_linked.cfm", which tells the user that the KSA has already been linked to the given Job.
If a record in Table: JobKSAs containing frn_JobID and frn_KSAID does not already exist, then I want it to be added to Table: JobKSAs, and for the user to be taken to "ksa_confirm.cfm", which tells the user that the KSA has been linked to the given job.
Below is my code for "ksa_au_pro.cfm".
Thank you for any help with this!
Luke
