B
Brian
I have a process that needs to first insert a header record in one table,
then detail records in another table where the newly-created PK in the header
table is the FK for the detail records.
My concern is capturing the auto-numbered PK of the just-inserted record so
that I can include it as the FK when I insert the detail records. As of now,
I insert the header record and immediately capture the DMax of the header
record PK to a variable, then pass that to the INSERT statement for the
detail records. Given that this takes all of perhaps 1/10 second, I suppose
there is little practical concern that another user may insert a header
record between the time I insert the header & capture the DMax, but is there
a way to actually capture the result of an INSERT statement and identify with
absolute certainty the record just inserted?
At first glance, the simple solution might appear to be binding the form to
the table and navigating to a new record. However, that would be very
difficult in this case, because the form in question is used to run perhaps
15 similar processes affecting different table combinations. It is a generic
form for processing various types of batch processes - the user selects which
batch process is to be run from a combo box, and all the updates/inserts are
done in VBA.
I suppose I could use a generic hidden control and set its RecordSource,
along with the form's RecordSource, at runtime.
Any other way?
then detail records in another table where the newly-created PK in the header
table is the FK for the detail records.
My concern is capturing the auto-numbered PK of the just-inserted record so
that I can include it as the FK when I insert the detail records. As of now,
I insert the header record and immediately capture the DMax of the header
record PK to a variable, then pass that to the INSERT statement for the
detail records. Given that this takes all of perhaps 1/10 second, I suppose
there is little practical concern that another user may insert a header
record between the time I insert the header & capture the DMax, but is there
a way to actually capture the result of an INSERT statement and identify with
absolute certainty the record just inserted?
At first glance, the simple solution might appear to be binding the form to
the table and navigating to a new record. However, that would be very
difficult in this case, because the form in question is used to run perhaps
15 similar processes affecting different table combinations. It is a generic
form for processing various types of batch processes - the user selects which
batch process is to be run from a combo box, and all the updates/inserts are
done in VBA.
I suppose I could use a generic hidden control and set its RecordSource,
along with the form's RecordSource, at runtime.
Any other way?