Results 1 to 3 of 3
  1. #1
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2003
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368

    Code deletes too much records

    Guys i am puzzled ...



    My form has a piece of code in it that deletes records older then two years :

    Code:
    Dim dteExpiry As Date
    Dim strSQLDelete As String
    dteExpiry = DateAdd("yyyy", -2, Date)
    strSQLDelete = "DELETE from tblWaarschuwingen WHERE tblWaarschuwingen.datum2 <= #" & dteExpiry & "#;"
    DoCmd.RunSQL strSQLDelete
    But...

    As it turns out it does not only delete records older then two years, but also records related with personell number to that record !!
    Now i do relate records by personell number (its NOT the primairy key though) but in this case its not meant to do that !

    Help !

  2. #2
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2003
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Never mind i found the error.
    It seems that i had a relationship defined that connected the records.
    I deleted the relationship, now i only hope that other functions still work :P
    But i guess ill find that out soon enough.

    If anyone had an addition to the code that only deletes records older then two years (negating the relationship) that would be more then welcome.

  3. #3
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    You can still have a relationship between the two Tables, just make sure that "Cascade Delete Related Records" isn't checked.

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

Similar Threads

  1. Replies: 2
    Last Post: 01-17-2012, 10:15 AM
  2. Importing Data from excel deletes queries
    By piyush85 in forum Access
    Replies: 5
    Last Post: 08-08-2011, 12:33 PM
  3. Access Report deletes grouped data.
    By matt123 in forum Database Design
    Replies: 5
    Last Post: 07-07-2011, 09:19 AM
  4. Macro Export Deletes it's Destination File
    By maxCohen in forum Access
    Replies: 2
    Last Post: 05-06-2011, 09:07 PM
  5. Replies: 7
    Last Post: 12-15-2010, 09:46 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