R
Ray Todd Jr
I am getting error 3201 (You cannot add or change a record because a related
recored is required in table 'taDEFENDANTS'.)
I understand WHAT the error means, however, what I don't know is HOW to fix
it using SQL.
What I am trying to do is when I print a letter, to have a note put into the
notes table that a letter was printed and the date printed.
The two tables:
taDefendants taDEFENDANTSNotes
DefendantID (PK) DefNotesID (PK)
PropertyID DefendantID (FK)
BatchID ...
....
Private Sub cmdCreateBatch_Click()
'On Error Goto Err_Handler
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSql As String
Dim lngBatchID As Long
Dim lngKt As Long
Dim lngKtSubtotal1 As Long
Dim lngKtSubtotal2 As Long
Dim strDefNote As String
Dim lngDefendantID As Long
strDefNote = "Letter Printed on " & Now()
'Create the new batch, and get the number.
Set db = CurrentDb()
Set rs = db.OpenRecordset("taBATCH", dbOpenDynaset, dbAppendOnly)
rs.AddNew
rs!BatchDateTime = Now()
lngBatchID = rs!BatchID
rs.Update
rs.Close
'Give this batch number to all members who have not been printed.
strSql = "Update taDefendants set BatchID= " & lngBatchID & " Where
BatchID is Null;"
db.Execute strSql, dbFailOnError
lngKtSubtotal1 = db.RecordsAffected
strSql = "Insert into taDefendantsNotes (DefendantID, DefNote) " _
& "values (" & lngDefendantID & ", '" & strDefNote & "')"
db.Execute strSql, dbFailOnError
Any help/suggestions would be appreciated.
Thanks,
Ray.
recored is required in table 'taDEFENDANTS'.)
I understand WHAT the error means, however, what I don't know is HOW to fix
it using SQL.
What I am trying to do is when I print a letter, to have a note put into the
notes table that a letter was printed and the date printed.
The two tables:
taDefendants taDEFENDANTSNotes
DefendantID (PK) DefNotesID (PK)
PropertyID DefendantID (FK)
BatchID ...
....
Private Sub cmdCreateBatch_Click()
'On Error Goto Err_Handler
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSql As String
Dim lngBatchID As Long
Dim lngKt As Long
Dim lngKtSubtotal1 As Long
Dim lngKtSubtotal2 As Long
Dim strDefNote As String
Dim lngDefendantID As Long
strDefNote = "Letter Printed on " & Now()
'Create the new batch, and get the number.
Set db = CurrentDb()
Set rs = db.OpenRecordset("taBATCH", dbOpenDynaset, dbAppendOnly)
rs.AddNew
rs!BatchDateTime = Now()
lngBatchID = rs!BatchID
rs.Update
rs.Close
'Give this batch number to all members who have not been printed.
strSql = "Update taDefendants set BatchID= " & lngBatchID & " Where
BatchID is Null;"
db.Execute strSql, dbFailOnError
lngKtSubtotal1 = db.RecordsAffected
strSql = "Insert into taDefendantsNotes (DefendantID, DefNote) " _
& "values (" & lngDefendantID & ", '" & strDefNote & "')"
db.Execute strSql, dbFailOnError
Any help/suggestions would be appreciated.
Thanks,
Ray.