I have a button on a form that creates a new record, based on the current record, when the user clicks the button. The original code from the MASTER table worked fine. Now I need to add additional fields to the new record from another table: Related. When I added the code for the Related table, the fields in the Related table did not populate on the new record. Can someone please help? The code is below. Thanks
Code:
Private Sub Add_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rs2 As DAO.Recordset
On Error Resume Next
Set db = CurrentDb
Set rs = CurrentDb.OpenRecordset("SELECT * FROM [MASTER]")
rs.AddNew
rs![Number] = Me. Number.Value
rs![Title] = Me.Title.Value
rs![Year] = Me.Year.Value
rs![Schedule] = Me.Schedule.Value
rs![Comments] = Me.Comments.Value
rs![Statement] = Me.Statement.Value
rs![HistoryChanges] = Me.HistoryChanges.Value
rs![Orig_PubDate] = Me.Orig_PubDate.Value
rs![Last_PubDate] = Me.Last_PubDate.Value
rs![Keywords] = Me.Keywords.Value
rs.Update
rs.Close
db.Close
Set rs = Nothing
Set db = CurrentDb
Set rs2 = CurrentDb.OpenRecordset("SELECT * FROM [Related]")
rs2.AddNew
rs2![Related_1] = Me.Related_1.Value
rs2![Related_2] = Me.Related_2.Value
rs2![Related_ 3] = Me.Related_3.Value
rs2![Related_ 4] = Me.Related_4.Value
rs2![Related_ 5] = Me.Related_5.Value
rs2.Update
rs2.Close
Set rs2 = Nothing
db.Close
DoCmd.Close
End Sub
Comment