Setting values into a table using the PK of the just created record

D

dan.neely

I have a form for updating a table. Some of the fields are user
defined defaults. I'm also trying to do the same for records being
inserted into a link table. Since the 'default' values can change
from one batch of data being entered to the next I can't set them in
the table design itself.

My form has comboboxes and listboxes to set the defaults with. The
main form is then accessed in datasheet format as an embedded child
form of the main one. The datasheet childform has a childform of its
own to show the values in the link table.

The way I want it to work is that as soon as the user begins to enter
data into the new row of the datasheet all the fields that have a
default are automatically initialized to the values selected above,
and the new rows in the link table are created and viewable if
childform for that is shown.


I've put my code in the begin insert event which works fine for the
data that goes into the main table, but I can't add new records into
the link table at that point. Apparently because one of the values
I'm putting into it as an FK is the PK of the main table which doesn't
'exist' when the query to add them is executed. Is there a different
event I should be using for this, and if so which?
 
A

Allen Browne

Dan, your understanding is correct. In a correctly designed database, you
will not be able to create the child record until the parent record exists.

Therefore, use the AfterInsert event of the main form to create the child
records.
 

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