Results 1 to 7 of 7
  1. #1
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105

    Whats the easiest way to delete a record with related records?


    I was reading that cascade delete option will do this, but is that only if you are deleting the record right from the table?

    I want to have a button click event that will delete the record and all related records...anybody have any examples or ideas on how this would work?

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    code behind the button to delete the records table by table.

  3. #3
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by RedGoneWILD View Post
    I was reading that cascade delete option will do this, but is that only if you are deleting the record right from the table?

    I want to have a button click event that will delete the record and all related records...anybody have any examples or ideas on how this would work?
    Cascade deletes must be checked in each child table of a parent table in the relationships window (or elsewhere). If you don't select this option, deleting a parent record will orphan (leave behind) child records that are sitting in all the related tables associated with that main table.

    And NO, cascades can be done through forms as well, not just tables. As a matter of fact, it would be pointless for MS to even program access to delete from tables at all, considering the fact that it is standard practice not to allow end users to access raw data (thus, tables).

    Make sure that option is checked for all the appropriate tables. Then delete a parent record...access will do the rest automatically.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by ajetrumpet View Post
    ...If you don't select this option, deleting a parent record will orphan (leave behind) child records that are sitting in all the related tables associated with that main table.
    Adam,
    Assuming RI is turned on, Access will throw an error when you attempt this.

  5. #5
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by RuralGuy View Post
    Adam,
    Assuming RI is turned on, Access will throw an error when you attempt this.
    Yes I forgot to mention. Thank you for adding that in. I'm having brain malfunction, what is RI?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    RI = Referential Integrity

  7. #7
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by RuralGuy View Post
    RI = Referential Integrity
    *kickstart*

    OK, my CPU is back online.

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

Similar Threads

  1. Replies: 5
    Last Post: 08-20-2010, 09:10 AM
  2. Delete all records in a field
    By cotri in forum Forms
    Replies: 6
    Last Post: 01-29-2010, 02:44 PM
  3. #delete records
    By supernova122 in forum Access
    Replies: 0
    Last Post: 07-08-2009, 08:41 AM
  4. Delete a record
    By f.crocco in forum Programming
    Replies: 1
    Last Post: 10-08-2007, 07:28 AM
  5. Delete all records in a table?
    By bob646 in forum Access
    Replies: 1
    Last Post: 05-20-2007, 11:41 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