Updating Access Database through Excel Userform - Primary/Foreign Keys

Jaycrone

New Member
Joined
Aug 16, 2016
Messages
3
Hi,

I'm relatively new to using Excel to add records to an access database.
I have the following code that when the user presses the submit button it adds the record within access database.

Code:
Set db = OpenDatabase(DatabasePath)
'Open the 'Lab_Submissions' table within the database
Set rst = db.OpenRecordset("tbl_Colleagues")

'This section populates the information in the UserForm into Access Database, depending on what table it is to go into.
    On Error GoTo ErrorHandling
    
    rst.AddNew
        rst.Fields("ReferenceNumber") = UserForm1.txtbox_RefNum.Value
        rst.Fields("FName") = UserForm2.txtbox_ColleagueFName.Value
        rst.Fields("LName") = UserForm2.txtbox_ColleagueLName.Value
        rst.Fields("Role") = UserForm2.txtbox_ColleagueRole.Value
        rst.Fields("eMail") = UserForm2.txtbox_ColleagueEmail.Value
        rst.Fields("PhoneNumber") = UserForm2.txtbox_ColleagueContactNum.Value
        rst.Fields("Enrolled").Value = True
    
        rst.Update
        
rst.Close
Set rst = db.OpenRecordset("tbl_LineManagers")

I want to then replicate above for the colleagues manager, details of which are added to the "tbl_LineManagers" table in access. The "tbl_Colleagues" table contains a field called "ManagerID" which has a 1:M relationship from the LineManager table, however when I add a record this field remains blank.

How can I get it so that the "ManagerID" field in "tbl_Managers" is pulled through to the "ManagerID" field in "tbl_Colleagues"?

Thanks.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,224,940
Messages
6,181,891
Members
453,068
Latest member
DCD1872

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top