|
-
Mar 9th, 2007, 06:15 AM
#1
Thread Starter
Frenzied Member
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:
Private Sub mnuFileClear_Click()
If MsgBox("Are you sure you wish to delete old session data?" & vbCrLf & _
vbCrLf & "This will remove session data older than six months!", _
vbQuestion + vbYesNo + vbDefaultButton2) = vbNo Then Exit Sub
Dim lRecCount As Long, sQuery As String
sQuery = "DELETE FROM Visits WHERE sDate<" & _
FormatDateTime(DateAdd("m", -6, Now), vbShortDate) & _
";"
Debug.Print sQuery
ConnOBData.Execute sQuery, lRecCount
Debug.Print lRecCount & " affected records!"
End Sub
 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
-
Mar 9th, 2007, 06:21 AM
#2
Re: ms access delete records older than six months
You have to surround the date value with the # signs:
VB Code:
Dim lRecCount As Long, sQuery As String
sQuery = "DELETE FROM Visits WHERE sDate < #" & _
FormatDateTime(DateAdd("m", -6, Now), vbShortDate) & _
"#;"
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."
-
Mar 9th, 2007, 06:27 AM
#3
Thread Starter
Frenzied Member
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
-
Mar 9th, 2007, 06:27 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|