I have a Form with a button: that when clicked will do the following
Add the Now() date to a table, a sub table and two sub sub tables (I want to add more data but started small)
Parent table tblDirectorsDD
PK: DirDDKey
FK: DDKey
Child table: tblDirectorsIdentity
PK: DirKey
FK: CiKey
Child Child table1: tblDirectorsGoogle
PK: DDKey
FK: DirKey
Child Child table2: tblDirectorsInsolvency
PK: DDKey
FK: DirKey
Private Sub BtnStartDirectors_Click() (From a from at the tblDirectorsDD level)
Me.DirectorsDDDateStarted = Now()
If Me.Dirty Then
Me.Dirty = False
End If
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("tblDirectorsIdentity")
rs.AddNew
rs!CIKey = Me.DirDDKey
rs!DirectorDateStarted = Now()
rs.Update
Set rs = CurrentDb.OpenRecordset("tblDirectorsGoogle")
rs.AddNew
rs!DirKey = Me.DirDDKey
rs!GoogleDateStarted = Now()
rs.Update
Set rs = CurrentDb.OpenRecordset("tblDirectorsInsolvency")
rs.AddNew
rs!DirKey = Me.DirDDKey
rs!InsolvencyDateStarted = Now()
rs.Update
End Sub
My error comes in the form of a 3021 Error at the second rs.Update saying I can not add or change a record because a related record is required in tbldirectoorsidentity.
I have used this code elsewhere in the database and it works fine to update multiple tables with data, but this is the first time I'm hitting this error. When I open table tbldirectorsidentit, the PK is complete, the FK is populated and the date is showing. So its clearly updating the first table, why wot it do the same to the child tables.
Mousing over the vba shows that the correct data is ready to be saved, but what is missing to complete the save?
Regards