Sub AddCustomerJob()
On Error GoTo ErrHandler
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim lngID As Long
Set db = CurrentDb()
Set rst = db.OpenRecordset("Customers", DAO.RecordsetTypeEnum.dbOpenTable)
With rst
.AddNew
lngID = .Fields("CustID") [green]'capture autonumber for new record[/green]
.Fields("CustName") = "Arnold Schwarznegger"
.Fields("Gender") = "Male"
.Fields("Age") = "49"
.Update
End With
rst.Close
Set rst = db.OpenRecordset("Jobs", DAO.RecordsetTypeEnum.dbOpenTable)
With rst
.AddNew
.Fields("CustID") = lngID [green]'foreign key link to parent table[/green]
.Fields("StartDate") = "1/1/04"
.Fields("CompleteDate") = "12/31/04"
.Fields("JobName") = "World Gym"
.Fields("Cost") = "650000"
.Update
End With
ExitHere:
On Error Resume Next
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Sub
ErrHandler:
Debug.Print Err, Err.Description
Resume ExitHere
End Sub