Delete data more than 2 months old

A

AJCB

Hi there.

I have a field in a table which shows the date and time that a record was
created in Access.

I am wanting to run a query that will automatically delete data that is more
than 2 months old, but I cannot figure out what string to put in the query.

Can anyone help me?

Regards
AJ
 
A

Allen Browne

DELETE FROM [YourTableNameHere]
WHERE [YourDateTimeFieldHere] < DateAdd("m", -2, Date());
 
D

Dennis

Create a query with your table as its source. Create a column in the query
like this
HowOld: DateAdd("m",2,[Date Created])
In the criteria fior this column put
Check the query return the correct results and then change its type to a
delete query
 
A

AJCB

Hi Dennis.

This did not work. I didn't get an error message, but all it put in the
field was the date and the time that the record was created.

Do you have any other ideas?

Dennis said:
Create a query with your table as its source. Create a column in the query
like this
HowOld: DateAdd("m",2,[Date Created])
In the criteria fior this column put
Check the query return the correct results and then change its type to a
delete query

AJCB said:
Hi there.

I have a field in a table which shows the date and time that a record was
created in Access.

I am wanting to run a query that will automatically delete data that is more
than 2 months old, but I cannot figure out what string to put in the query.

Can anyone help me?

Regards
AJ
 
D

Dennis

It works OK but obviously I cannot see what you have done. Have you tried it
Allen's way instead ?

AJCB said:
Hi Dennis.

This did not work. I didn't get an error message, but all it put in the
field was the date and the time that the record was created.

Do you have any other ideas?

Dennis said:
Create a query with your table as its source. Create a column in the query
like this
HowOld: DateAdd("m",2,[Date Created])
In the criteria fior this column put
Check the query return the correct results and then change its type to a
delete query

AJCB said:
Hi there.

I have a field in a table which shows the date and time that a record was
created in Access.

I am wanting to run a query that will automatically delete data that is more
than 2 months old, but I cannot figure out what string to put in the query.

Can anyone help me?

Regards
AJ
 
A

AJCB

I will try, but I am not really that confident using SQL queries, as I
usually cannot get them to work.

Dennis said:
It works OK but obviously I cannot see what you have done. Have you tried it
Allen's way instead ?

AJCB said:
Hi Dennis.

This did not work. I didn't get an error message, but all it put in the
field was the date and the time that the record was created.

Do you have any other ideas?

Dennis said:
Create a query with your table as its source. Create a column in the query
like this
HowOld: DateAdd("m",2,[Date Created])
In the criteria fior this column put
Now()
Check the query return the correct results and then change its type to a
delete query

:

Hi there.

I have a field in a table which shows the date and time that a record was
created in Access.

I am wanting to run a query that will automatically delete data that is more
than 2 months old, but I cannot figure out what string to put in the query.

Can anyone help me?

Regards
AJ
 
J

John W. Vinson

I am wanting to run a query that will automatically delete data that is more
than 2 months old,

Why?

You'll NEVER need to see historical data?

Bear in mind that deleting data will NOT free up space in your database (until
you Compact), and if you have suitable indexes, won't much affect the speed of
your queries, unless you have hundreds of thousands of records.
but I cannot figure out what string to put in the query.

< DateAdd("m", 2, Date())

will delete all records older than two months ago today. BACK UP YOUR DATABASE
first.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top