Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating child related record using rs

Status
Not open for further replies.

Domino2

Technical User
Jun 8, 2008
475
GB
I get the error coming up "No record" when I try to add a record in a child record. Problem trying to get main tables AutoNumber to put in foreign key of child related record. I cannot seem to find how to insert the foreign key at the right time

Code:
Dim i As Integer
 Dim sql As String
 Dim LKS As String
 Dim GG As Integer
 
 Dim rs As DAO.Recordset
 Dim rss As DAO.Recordset
 Dim db As DAO.Database
 Set db = CurrentDb()
 Set rs = db.OpenRecordset("MainTable1", dbOpenDynaset)
 Set rss = db.OpenRecordset("QIssueKeywords", dbOpenDynaset)
  
        rs.AddNew
        rs!DateLogged = Me.DLOG
        rs!RequestNumber = Me.RQN
        rs!Priority = Me.PRY.Column(1)
        rs!ITContact = Me.ITCNT.Column(1)
        rs!Category = Me.CATY.Column(1)
        rs!IssueContact = Me.ICNT
        rs!Status = "Active"
        rs!Qissue = Me.BSUM
        rs.Update
        
        
        rss.AddNew
        rss!ID2 = rs!ID1
        rss!TKeyword = "test"
        rss.Update
        
        rs.Close
        rss.Close
        Set rs = Nothing: Set rss = Nothing
        Set db = Nothing

ID1 is the Primary Key (Table 1)
ID2 is the foreign key (Table 2)

Thanks
 
Managed to sort it, using variable HHH to pass over

Code:
' Maintable1 Add record
        rs.AddNew
        rs!DateLogged = Me.DLOG
        rs!RequestNumber = Me.RQN
        rs!Priority = Me.PRY.Column(1)
        rs!ITContact = Me.ITCNT.Column(1)
        rs!Category = Me.CATY.Column(1)
        rs!IssueContact = Me.ICNT
        rs!Status = "Active"
        rs!Qissue = Me.BSUM
        HHH = rs!ID1
        rs.Update
        
        ' QissueKeywords add record
        rss.AddNew
        rss!ID2 = HHH
        rss!TKeyword = "test"
        rss.Update
        
        rs.Close
        rss.Close
        Set rs = Nothing: Set rss = Nothing
        Set db = Nothing

Maybe a better way, but it works thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top