Board index » delphi » Master-Detail Question?

Master-Detail Question?

I have a data module with 2 tables -  I have two forms -
Form1 has table that is master - Form 2 has table that is
detail -  master table has a field that will contain the
actual number of detail records.  My question is what is the
best way to update the #of rec's field in the master table.
My 1st thought was to add code to the after delete and after
insert events for detail record and subtract/add 1 to the
field in the master.  The after delete works fine but  i'm
having trouble with the after insert (it increments the
master table) but never inserts record in the detail table
(i'm using the standard navigator component). Any ideas?

thanks in advance

terry b


Re:Master-Detail Question?

AfterInsert fires when the new record has been created in memory.  It does
not exist in the table until it has been posted (and committed if you are
using transactions).  You need to set a flag in AfterInsert and if the flag
is true increment the count and clear the flag in AfterPost.

Bill Todd
(Sorry but TeamB cannot answer questions received via email)
(Remove nospam from my email address to contact me for any other reason)

Other Threads