Results 1 to 2 of 2
  1. #1
    jessmith07 is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    4

    Primary Key from main form/table to be ID in other forms/tables

    I am building a database in Acess 2007 and I have three tables housing data...one table houses the main data, one houses fiscal data and the third houses accounting line data. tblMain has a primary key set to auto number, tblFiscal and tblAccountingLine both have their ID field set to number (no primary key, as they need to allow duplicate values).



    What I want is to have the primary key from tblMain be automatically inserted into the ID field of tblFiscal and tblAccountingLine when new records are added...

    By way of example...In the forms, themselves, if record 9 in frmMain is active, and record 9 also has already had information entered in frmFiscal and frmAccountingLine, then clicking the buttons to display the frmFiscal and frmAccountingLine does bring up the correct information for record 9.

    What I want relates to new record entries. So, if I'm making a new entry in frmMain for record 10, and then click the buttons to add new data into frmFiscal and frmAccountingLine, I want the record number from frmMain (i.e. primary key in tblMain) to auto-populate the ID fields in frmFiscal and frmAccountingLine, thereby updating ID field tblFiscal and tblAccountingLine.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    What your structure should look like (IMO)

    Code:
    tblMain
    ----------
    MainID_PK  Autonumber
    other data fields
    ...
    ...
    
    tblFiscal
    ------------
    FiscalID_PK Autonumber
    MainID_FK  Long ' foreign key link to table tblMain
    other fields
    ...
    ...
    
    tblAccountingLine
    -------------------
    AccntLineID_PK Autonumber
    MainID_FK Long  ' foreign key link to table tblMain
    other fields
    ...
    ...
    I always have an autonumber as the PK in a table. The autonumber field just ensures you have a unique field in the record - nothing else. (PKs and FKs are not visible to the users.)

    HOW you get MainID_PK into the foreign key fields in the other two tables depends - you can use a main form/sub form arraignment or you can use code. I tend to use code - and not so much sub forms.


    Here is a link to an example:
    http://msofficeuser.com/pages/access...crosoft-access

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 03-31-2012, 01:38 PM
  2. Replies: 8
    Last Post: 03-22-2012, 08:48 AM
  3. Linking tables to show primary key from main table
    By Mark_435 in forum Database Design
    Replies: 5
    Last Post: 01-12-2012, 09:20 PM
  4. Replies: 12
    Last Post: 07-18-2011, 12:47 PM
  5. connecting many sub forms in one main form
    By Dasun in forum Programming
    Replies: 2
    Last Post: 07-01-2011, 02:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums