Results 1 to 7 of 7
  1. #1
    davidson12 is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    4

    Parent/Child Append Question

    Hello Everyone --

    I've been working on an audit database for my company and I'm running into some issues with appending information to a child table.

    Here's the basic structure of the two tables, and what I'm looking to do:

    Table A (parent)
    • Audit ID (Autonumber, Primary Key)
    • Customer ID
    • Audit Trigger Date
    Table B (child)


    • Audit ID
    • Account Number
    • Pass/Fail

    Table B would contain a sample of 20 customer accounts from customer ID above. I currently have a one-to-many join on Audit ID between the two tables. I can append new rows to table A without issue, but I'm just not sure what is the best way to append my 20 rows to table B without violating my relationship. Any suggestions?

  2. #2
    llkhoutx is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Houston, Texas USA
    Posts
    373
    Add a primary key to the child table.

    Parent child relationships work very, very well in form, subform environments. However, never create a child (subform) record without a parent (form) record, if you do, you'll have orphan an child with no parent. Always create the parent record first, regardless of the method used.

    If you create the relationship between the two tables in the Relationship window with cascading updates and deletes, you can update the tables in the table view, while displaying the child table. Note that the foreigh key (to the parent table) will be automatically updated, but not displayed.

  3. #3
    davidson12 is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    4
    Quote Originally Posted by llkhoutx View Post
    Add a primary key to the child table.

    Parent child relationships work very, very well in form, subform environments. However, never create a child (subform) record without a parent (form) record, if you do, you'll have orphan an child with no parent. Always create the parent record first, regardless of the method used.

    If you create the relationship between the two tables in the Relationship window with cascading updates and deletes, you can update the tables in the table view, while displaying the child table. Note that the foreigh key (to the parent table) will be automatically updated, but not displayed.
    I left out some information. I do have a primary key on my child table, it's an account audit ID which is an autonumber. I am able to create records in my child table via a form/subform, but what I'd like to do is have access run a job nightly which will create 1 record in my parent table and 20 records in my child table.

  4. #4
    llkhoutx is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Houston, Texas USA
    Posts
    373
    What's in those 20 records? Are they empty?

  5. #5
    davidson12 is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    4
    Quote Originally Posted by llkhoutx View Post
    What's in those 20 records? Are they empty?
    No, the 20 records would represent 20 account numbers. Then each one of the 20 accounts would have items that would be marked as essentially "yes/no" fields.

    Ideally the database will refresh overnight and if a series of business rules are met then one record would be appended to the parent table (customer ID) and 20 records (customer account numbers) would be appended to the child table.

  6. #6
    llkhoutx is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Houston, Texas USA
    Posts
    373
    Here's the code to create the 20 records

    Code:
    Sub CreateRecords(PrimaryKey as long)
    dim db as database
    dim rs 
    as recordset
    dim i 
    as integer
    set db
    =currentdb
    set rs
    =db.openrecordset("ChildTableBName",dbopendynaset)
    for 
    1 to 20 ' loop 20 times
      rs.addnew ' 
    add a new record to recordset
         rs
    !ForeignKey PrimaryKey 
         rs
    !accountnumber = ---- I have no idea where the account Noscome from
      rs
    .update ' save the record
    Next
    rs.close
    db.cloise
    set rs=nothing
    set db=nothing
    End Sub 

  7. #7
    ychartrand is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Jan 2015
    Posts
    1
    Thanks, found this helpful for related issue.
    Regard, ychartrand

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

Similar Threads

  1. Append query won't append
    By yelkenli in forum Queries
    Replies: 5
    Last Post: 02-12-2010, 11:19 AM
  2. Parent/Child subform
    By Jerry8989 in forum Forms
    Replies: 1
    Last Post: 09-18-2009, 07:27 AM
  3. Pulling most recent data from child table
    By davidv43 in forum Access
    Replies: 0
    Last Post: 02-07-2009, 11:36 AM
  4. SubForm to Parent
    By henryclay in forum Forms
    Replies: 2
    Last Post: 11-15-2006, 09:44 AM
  5. SubForms to Parent
    By henryclay in forum Forms
    Replies: 2
    Last Post: 10-27-2006, 07:14 AM

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