Results 1 to 4 of 4

Thread: ms access delete records older than six months [Resolved]

  1. #1

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Resolved ms access delete records older than six months [Resolved]

    ok, my database connection is working fine, can delete etc.

    need to mass delete tho, all records older than six months i wanna delete.

    pretty simple, except it isnt happening, im thinking problem wi me query.

    vb Code:
    1. Private Sub mnuFileClear_Click()
    2.    
    3.     If MsgBox("Are you sure you wish to delete old session data?" & vbCrLf & _
    4.               vbCrLf & "This will remove session data older than six months!", _
    5.               vbQuestion + vbYesNo + vbDefaultButton2) = vbNo Then Exit Sub
    6.              
    7.     Dim lRecCount As Long, sQuery As String
    8.        
    9.     sQuery = "DELETE FROM Visits WHERE sDate<" & _
    10.              FormatDateTime(DateAdd("m", -6, Now), vbShortDate) & _
    11.              ";"
    12.              
    13.              Debug.Print sQuery
    14.     ConnOBData.Execute sQuery, lRecCount
    15.    
    16.     Debug.Print lRecCount & " affected records!"
    17.    
    18. End Sub


    Quote Originally Posted by DEBUG
    DELETE FROM Visits WHERE sDate<09/09/2006;
    0 affected records!
    anyone spot the error? :S meh. i av got records wi the dates in march,april,may,june in 2005/2006 so should work? :S

    ta
    Last edited by Hack; Mar 9th, 2007 at 07:01 AM. Reason: Added green "resolved" checkmark Last edited by wpearsall : Today at 06:26 AM. Reason: Resolved
    Wayne

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: ms access delete records older than six months

    You have to surround the date value with the # signs:


    VB Code:
    1. Dim lRecCount As Long, sQuery As String
    2.  
    3. sQuery = "DELETE FROM Visits WHERE sDate < #" & _
    4. FormatDateTime(DateAdd("m", -6, Now), vbShortDate) & _
    5. "#;"
    Last edited by Mark Gambo; Mar 9th, 2007 at 06:27 AM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Re: ms access delete records older than six months [Resolved]

    cheers mate, that did it. [i knew it was gonna b somethin simple lol :S ta
    Wayne

  4. #4
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: ms access delete records older than six months [Resolved]

    Any time
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width