Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 243007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:53:07+00:00 2026-05-11T20:53:07+00:00

I have two tables: OutputPackages (master) |PackageID| OutputItems (detail) |ItemID|PackageID| OutputItems has an index

  • 0

I have two tables:

OutputPackages (master)

|PackageID|

OutputItems (detail)

|ItemID|PackageID|

OutputItems has an index called ‘idxPackage’ set on the PackageID column. ItemID is set to auto increment.

Here’s the code I’m using to insert masters/details into these tables:

//fill packages table
for i := 1 to 10 do
begin
  Package := TfPackage(dlgSummary.fcPackageForms.Forms[i]);

if Package.PackageLoaded then
begin
  with tblOutputPackages do
  begin
    Insert;
    FieldByName('PackageID').AsInteger := Package.ourNum;
    FieldByName('Description').AsString := Package.Title;
    FieldByName('Total').AsCurrency := Package.Total;
    Post;
  end;

  //fill items table
  for ii := 1 to 10 do
  begin
    Item := TfPackagedItemEdit(Package.fc.Forms[ii]);
    if Item.Activated then
    begin
      with tblOutputItems do
      begin
        Append;
        FieldByName('PackageID').AsInteger := Package.ourNum;
        FieldByName('Description').AsString := Item.Description;
        FieldByName('Comment').AsString := Item.Comment;
        FieldByName('Price').AsCurrency := Item.Price;
        Post; //this causes the primary key exception
      end;
    end;
  end;
end;

This works fine as long as I don’t mess with the MasterSource/MasterFields properties in the IDE. But once I set it, and run this code I get an error that says I’ve got a duplicate primary key ‘ItemID’.

I’m not sure what’s going on – this is my first foray into master/detail, so something may be setup wrong. I’m using ComponentAce’s Absolute Database for this project.

How can I get this to insert properly?

Update

Ok, I removed the primary key restraint in my db, and I see that for some reason, the autoincrement feature of the OutputItems table isn’t working like I expected. Here’s how the OutputItems table looks after running the above code:

ItemID|PackageID|
1     |1        |
1     |1        |
2     |2        |
2     |2        |

I still don’t see why all the ItemID values aren’t unique…. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:53:07+00:00Added an answer on May 11, 2026 at 8:53 pm

    Does using insert rather than append on the items table behave any differently? My guess here is that the append on the detail “sees” an empty dataset, so the auto-increment logic starts at one, the next record two, etc even though those values have already been assigned… just to a different master record.

    One solution I used in the past was to create a new table named UniqueNums that persisted the next available record id number that I was going to use. As I used a number, I would lock that table, increment the value and write it back then unlock and use. This might get you around the specific issue you are having.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables Master Detail In the Master & Detail table I get
I have two tables: Transactions and TransactionAgents. TransactionAgents has a foreign key to Transactions
I have two tables, orders and old_orders. Each table has some similar fields and
I have two tables that are all the same, except one has a timestamp
I have two tables called lawyer & client.And they are the users of my
I have two tables Order , OrderStatus . Order has OrderId (pk), OrderStatusId (fk)
I have two tables that are joined together. A has many B Normally you
I have two tables in my database, called ratings and movies . Ratings: |
I have two tables, works and artists. Every artist has multiple works. Is it
I have two tables i need to query One called horse which contains the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.