In the following routine, I add a record to the first table and store its ID. I want to add a record to another table but I want to store the ID from the first table into a linking field in the second table.
Whats happening is, the second table is getting 2 records added. 1 has a linkID = 0 then there is another record with the proper value. So in essence, its duping on the
rs.update in the attached code in the function WriteQRRecord.
Can someone shed some light on this,...Thanks much.
I added the code....
'-- add record to first table to link to and works fine
Dim db As Database
Dim rs As Recordset
Dim lngID As Long
Set db = CurrentDb
Set rs = db.OpenRecordset("Inv")
rs.AddNew
rs("Inve") = Me.txtInv
rs("FamNo") = cboFamily.Column(0)
rs("FamName") = Me.cboFamily.Column(1)
lngID = rs("ID")
rs.Update
Set db = Nothing
Set rs = Nothing
'-- add record to the next table
WriteQRRecord (lngID)
Exit_Command33_Click:
Exit Sub
Err_Command33_Click:
MsgBox Err.Description
Resume Exit_Command33_Click
End Sub
Private Sub WriteQRRecord(lngID As Long)
' This routine has duped records
On Error GoTo WriteQRRecord_Err
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("Questions_Responses")
rs.AddNew
rs("question") = Me.txtQuestion
rs("Response") = Me.txtResponse
rs("link_id") = lngID
rs.Update
Set db = Nothing
Set rs = Nothing
End Sub
Whats happening is, the second table is getting 2 records added. 1 has a linkID = 0 then there is another record with the proper value. So in essence, its duping on the
rs.update in the attached code in the function WriteQRRecord.
Can someone shed some light on this,...Thanks much.
I added the code....
'-- add record to first table to link to and works fine
Dim db As Database
Dim rs As Recordset
Dim lngID As Long
Set db = CurrentDb
Set rs = db.OpenRecordset("Inv")
rs.AddNew
rs("Inve") = Me.txtInv
rs("FamNo") = cboFamily.Column(0)
rs("FamName") = Me.cboFamily.Column(1)
lngID = rs("ID")
rs.Update
Set db = Nothing
Set rs = Nothing
'-- add record to the next table
WriteQRRecord (lngID)
Exit_Command33_Click:
Exit Sub
Err_Command33_Click:
MsgBox Err.Description
Resume Exit_Command33_Click
End Sub
Private Sub WriteQRRecord(lngID As Long)
' This routine has duped records
On Error GoTo WriteQRRecord_Err
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("Questions_Responses")
rs.AddNew
rs("question") = Me.txtQuestion
rs("Response") = Me.txtResponse
rs("link_id") = lngID
rs.Update
Set db = Nothing
Set rs = Nothing
End Sub