Solved

Access VBA SQL Delete Query

Posted on 2010-09-22
2
471 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
ID: 33738590
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
ID: 33738611
Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

932 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

15 Experts available now in Live!

Get 1:1 Help Now