Mathew
You have two issues here
First, the primary key
I suspect the problem is that the one record on the main form may not have been updated.
Access generates the autonumber as soon as the "insert" record event. In otherwords, as soon as you start typing in a new record, Access generates the autonumber. But this record with the autogenerated number has not been committed / written to the table.
This creates two problems
- Under some conditions, the same autonumber can be generated by different new record activities. (More likely under a multi-user application.)
- Related records that need the primary key do not have easy access to this number.
Before addressing "how to" for this problem, you actually have a bigger problem.
Your second table, from my perspective, is a "history" table, and you actually have a one-to-many relationship.
As part of the normalization process, each record should be uniquely identified. You could do this by RedispatchNo + Date + Time. But this may be awkward.
Your second table should be designed as...
ReDispatchHistoryTbl
HistoryID - primary key
RedispatchNo - foreign key ReDispatchTbl
DispatchDate
DispatchTime
CurrentMW - **
RequestedMW - **
** I am not sure if you actually need these two fields since it is on the master table - unless you are capturing different information. They should be in one location or the other.
Now getting back to your problem - grabbing the primary key from one form for use in the other.
If I am correct in that you have a one-to-many relationship, then a common approach is to use a form / subform approach. If this solution is acceptable to you, access to the primary key is extremely easy.
I have a "Call" tacking system used to track call resolution. The approach I use is as follows...
The main form captures basic information including the CallID. At the bottom of the form, I have tab form that captures other related information. One of the tabs has a subform that displays the captured "history" in a contineous subform. The subform displays basic info - date, time, brief descritpion. On the subform, a small command button can be clicked to open up the details for the specific history record.
When a new record is created, the end user fills in the basisc info - this generates (but does not commit) the CallID. The end user clicks a button and the same form associated to the command button on the history subform, opens up as a new record. The CallID is passed as the OpenArg (OpenArgument) when the form is opened, and assigned as to the foreign key, also called CallID, to the history record.
To recap...
- Main form for the primay table
- Contineous form (possibly as part of a tab form) display a brief record of the history.
- A single form for the history record.
- The single form for the history record is opened in two ways. A command button on the main form opens the history for a new record where the OpenArg passes the RedispatchNo. On the history contineous form, a command button opens up the single history form for the specific record. The command button wizard will do the grunt work for you.
Richard