I currently have a one to one relationship between two tables in MS Access like so:
Student Results
- StudentResultsID (primary key, autonumber)
- Various fields relating to the course.
AVETMISS Data
- StudentResultsID (primary key, long integer)
- Various fields relating to a specific, paper form that must be filled out by the student for each enrolment.
When the user adds a new record to Student Results (this occurs everytime a student is enrolled into a course) I want to create a matching record in AVETMISS Data. I thought this was a function of creating the relationship and enforcing referential integrity, however even with this option turned on I keep getting inconsistencies.
If there is a way to make this happen in the setup of the tables (or queries) and the relationship that would be my preferred solution.
If this is not possible, one solution that I think would work, but is much less ideal, is to rig the form for AVETMISS Data to run some code or macro when it is opened.
Something like this in the On Load property:
Does this StudentResultsID exist in AVETMISS Data?
Yes - Do nothing
No - Create new record with this StudentResultsID
EDIT: It’s occured to me that the ‘After Insert’ property in the Student Results form may be a better candidate for this kind of solution.
If I must resort to this solution I would really appreciate some guidance in this as I know next to nothing about Visual Basic and don’t want to learn it for a 3-line snippet of code.
Please note – During my research I found a lot of people questioning the reasoning behind using a one to one relationship. I have read the arguments against using these relationships and I am certain that it is completely necessary for my situation.
Based on your description, I think you may be able to solve this with no code.
Create a form based on Student Results and a second form based on AVETMISS Data. Then add that second form to a subform control on the first form. Set the link master/child property to StudentResultsID.
When in form view, the subform should display the AVETMISS Data row whose StudentResultsID matches the current row displayed in the parent form.
If no subform match exists for the current parent form StudentResultsID, you can add one by typing a value into any other the available subform bound data controls (other than StudentResultsID). When saved, that new record will have the same StudentResultsID as the parent form current row.
The link master/child property ensures the child link field (StudentResultsID) “inherits” the master field value.