Solved

Access VBA SQL Delete Query

Posted on 2010-09-22
2
470 Views
Last Modified: 2012-05-10
Ok the below code ask for data in last 30 or 31 dates.

How would I tweak it to delete everything BUT the last 30 or 31 days?

Private Sub cmdProcess_Click()

'Date_DateFellDuringLast30Or31Days

Dim SQL



SQL = "DELETE  * FROM Table1 "

SQL = SQL & "WHERE Table1.SalesDate Between dateserial(year(Date()),month(date()),day(date())) And dateserial(year(Date()),month(date()) -1,day(date()))"

CurrentDb.Execute SQL, dbFailOnError



MsgBox "Complete", vbOKOnly, "Process Complete"



End Sub

Open in new window

0
Comment
Question by:ca1358
2 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
Comment Utility
Private Sub cmdProcess_Click()
'Date_DateFellDuringLast30Or31Days
Dim SQL

SQL = "DELETE  * FROM Table1 "
SQL = SQL & "WHERE NOT (Table1.SalesDate Between dateserial(year(Date()),month(date()),day(date())) And dateserial(year(Date()),month(date()) -1,day(date())))"
CurrentDb.Execute SQL, dbFailOnError

MsgBox "Complete", vbOKOnly, "Process Complete"

End Sub
0
 

Author Closing Comment

by:ca1358
Comment Utility
Thank you!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now