SQL Coding Question

R

Ray Todd Jr

How do I pull the defendantID from the tadefendant table and place that value
into the tadefendantsnotes table via sql? See the sql code I have below and
the basic layout of the tables involved.

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) Autonumber DefNotesID (PK) Autonumber
PropertyID -long DefendantID (FK) long
BatchID -long ...
....


strSql = "Insert into taDefendantsNotes (DefendantID, DefNote) " _
& "values (" & lngDefendantID & ", '" & strDefNote & "')"
db.Execute strSql, dbFailOnError


Any help/suggestions would be appreciated.


Thanks,
 
D

Douglas J. Steele

That code looks like it should work. What happens when you try running it?
 
R

Ray Todd Jr

Hello Douglas:

I am getting error 3201 (You cannot add or change a record because a related
record is required in table 'taDEFENDANTS'.)

I understand WHAT the error means, however, what I don't know is HOW to fix
it using SQL.
 
S

Steve Sanford

The problem is he is not passing a value for "lngDefendantID ".

See microsoft.public.access.formscoding on 4/19/2008,

Subject: Getting Foreign Key from Parent Table for New Record via SQL


He posted the code he is using....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top