I am working with three DAO recordsets, rst0 and rstK are related. When I create a record for rst0 I want to take the primary key of that new record which is SystemID and relate it by adding the SystemID to the recordset rstK. Unfortunately I am not sure how to do this. I have the code to the best of my ability, if someone could help out that would be great.
:Code Start:
Dim rstO As DAO.Recordset
Dim rstT As DAO.Recordset
Dim rstK As DAO.Recordset
Set rstT = CurrentDb.OpenRecordset("Products")
Set rstO = CurrentDb.OpenRecordset("tblSystem")
Set rstK = CurrentDb.OpenRecordset("tblSystemDetail")
With rstT
.MoveFirst
Do While Not .EOF
rstO.AddNew
rstO!SystemName = !ProductName
rstO!SystemDescription = !ProductDescription
rstO!PictureLink = !PictureLink
rstO!SystemSummary = !ProductSummaryPrint
rstK.AddNew
'The line below is where I am trying to get the systemID,
'from the newly created system (rst0), and put it into
'rstK (for the relationship). Unfortunately the line of
'code doesn't work, and that is why I am posting here![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
rstK!SystemID = rst0!SystemID
rstK!ProductID = !ProductID
rstK!OrderQuantity = 1
rstO.Update
rstK.Update
.MoveNext
Loop
.Close
rstO.Close
rstK.Close
End With
Set rstT = Nothing
Set rstO = Nothing
Set rstK = Nothing
:End Code:
Thanks,
Eric
:Code Start:
Dim rstO As DAO.Recordset
Dim rstT As DAO.Recordset
Dim rstK As DAO.Recordset
Set rstT = CurrentDb.OpenRecordset("Products")
Set rstO = CurrentDb.OpenRecordset("tblSystem")
Set rstK = CurrentDb.OpenRecordset("tblSystemDetail")
With rstT
.MoveFirst
Do While Not .EOF
rstO.AddNew
rstO!SystemName = !ProductName
rstO!SystemDescription = !ProductDescription
rstO!PictureLink = !PictureLink
rstO!SystemSummary = !ProductSummaryPrint
rstK.AddNew
'The line below is where I am trying to get the systemID,
'from the newly created system (rst0), and put it into
'rstK (for the relationship). Unfortunately the line of
'code doesn't work, and that is why I am posting here
rstK!SystemID = rst0!SystemID
rstK!ProductID = !ProductID
rstK!OrderQuantity = 1
rstO.Update
rstK.Update
.MoveNext
Loop
.Close
rstO.Close
rstK.Close
End With
Set rstT = Nothing
Set rstO = Nothing
Set rstK = Nothing
:End Code:
Thanks,
Eric