Welcome to Dream.In.Code
Become an Expert!

Join 149,614 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,863 people online right now. Registration is fast and FREE... Join Now!




Auto delete records after certain time?

 
Reply to this topicStart new topic

Auto delete records after certain time?

cool263
6 Sep, 2007 - 01:55 PM
Post #1

New D.I.C Head
*

Joined: 17 Jul, 2007
Posts: 19


My Contributions
Hello all,

I'm trying to build a web page that will automatically delete records (in Access 2k) after a certain amount of time. I need to delete records that are older than a month of the current date. I've searched all over the internet trying to find examples of how to do this and the few that I've found don't seem to work for me.

Does anyone have an example that works? Either using an sql query or programmatically. I'm using Classic ASP (VBScript).

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Auto Delete Records After Certain Time?
6 Sep, 2007 - 09:49 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
I think something along these lines should do it for you...

CODE

<%

' Create our connection string to access
Dim constring
constring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=fullpathtomdbfilegoeshere"

' Setup our connection object
Dim con
Set con = server.createobject("ADODB.Connection")

' Open the connection
con.open constring

Dim theCutOffDate
theCutOffDate = DateAdd("m",-1,now())

' Put together the query and execute the delete
Dim sql
sql = "delete from tablename where datecolumn < #" & theCutOffDate & "#"
con.execute(sql)

Set con = Nothing
%>


That essentially creates a connection to the file (make sure it has the correct permissions on the file itself) and then deletes all entries which older than a month.

Enjoy!

User is offlineProfile CardPM
+Quote Post

cool263
RE: Auto Delete Records After Certain Time?
7 Sep, 2007 - 07:36 AM
Post #3

New D.I.C Head
*

Joined: 17 Jul, 2007
Posts: 19


My Contributions
QUOTE(Martyr2 @ 6 Sep, 2007 - 10:49 PM) *

I think something along these lines should do it for you...

CODE

<%

' Create our connection string to access
Dim constring
constring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=fullpathtomdbfilegoeshere"

' Setup our connection object
Dim con
Set con = server.createobject("ADODB.Connection")

' Open the connection
con.open constring

Dim theCutOffDate
theCutOffDate = DateAdd("m",-1,now())

' Put together the query and execute the delete
Dim sql
sql = "delete from tablename where datecolumn < #" & theCutOffDate & "#"
con.execute(sql)

Set con = Nothing
%>


That essentially creates a connection to the file (make sure it has the correct permissions on the file itself) and then deletes all entries which older than a month.

Enjoy!





Thanks Martyr2!


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 12:30AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month