Saving a Newly Created Record

L

Lloyd

My application has a summary table and two detail tables,
with one-to-one relationships between the summary table
and the detail tables. In the summary table I have a
button to go to the detail table. Code behind the button
opens the correct record in the correct detail table or
asks to create a new record. Below is the code to create
a new record in one of the detail tables - it "works"
(displays the correct data in a new record), but I am not
allowed to save the data. It says that I have a duplicate
value in an index.

If MsgBox("No Tracking Record Found. Create a New
One?", vbOKCancel) = vbOK Then
DoCmd.OpenForm "frmCTrackGenInfoDE", acNormal, , ,
acFormAdd
Me.[Grant#] = [Forms]![frmGrantSumDE].[Grant#]
Forms![frmCTrackGenInfoDE].[Grantee] = [Forms]!
[frmGrantSumDE].[Grantee]
Else
MsgBox ("Action Canceled")
End If

Note, that if I create a detail record that is not linked
to a record in the summary table, it saves fine. Grant#
is the key in all tables. I'm unsure if I need to focus
on the coding, bound fields or the original query to
resolve this problem.

Thanks for any help you can provide.

Lloyd
 
B

Bill

Open the table that contains the detail records in design view. Go to the
icon menu and select the one with the lightning bolt (Indexes). See which
fields have unique indexes. If there is more than one (the primary key)
which is defined as unique, decide if it is necessary, if not change it,
else be sure that value is unique for each new record. Sometimes in the
table or forms control definition, default values violate this and must be
changed.
HTH
 

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