Rolling Append & Delete

Thecherub

Man with a Mission
Local time
Today, 10:33
Joined
Jan 14, 2004
Messages
92
This has probably been answered but I need to do a Rolling Append and Delete to the Month and Day.

I've got the month allright but how do i modify it to account for the Day.

Criteria - "=DateAdd("m",-4,Date())"

Example
as of today anything Nov 12, 03 or before shou;d be removed but i've still got records from Nov 7th, 03 in the Data.

Thank you in advance
 
So, your criteria involves everything over 4 months old. What's the rule?

You mention getting the day involved but neglect to mention any rule that governs the selected by the criteria.
 
The DateSerial function might work better for your criteria:
DateSerial(Year(Date),Month(Date)-4,Day(Date))

Subtracting 4 from the month will adjust the year properly.
 
The fact that you say anything on a specific day and before should be removed then you shouldn't use the = sign but use the less than or equal to operator ( <= ).
 
Here is the code for the query

INSERT INTO [Data Archive] ( [Employee number], Type, [Date], Comment )
SELECT [Absent Data].[Employee number], [Absent Data].Type, [Absent Data].Date, [Absent Data].Comment
FROM [Absent Data]
WHERE ((([Absent Data].Date)<=DateAdd("m",-4,Date())));

Mile

I need to have anything older than 4 months removed to the archive. so if todays date is april 12, 04 any thing before jan 12, 04 should be archived.

does that explain it?
 
Re: Here is the code for the query

INSERT INTO [Data Archive] ( [Employee number], Type, [Date], Comment )
SELECT [Absent Data].[Employee number], [Absent Data].Type, [Absent Data].Date, [Absent Data].Comment
FROM [Absent Data]
WHERE [Absent Data].[Date] <= DateSerial(Year(Date()),Month(Date())-4,Day(Date());


Date, however, is a bad choice for a field name as it's a Reserved Word in Access.
 
I did use that

The fact that you say anything on a specific day and before should be removed then you shouldn't use the = sign but use the less than or equal to operator ( <= ).

I did use that my paste somhow excluded that.

the criteria should read "<=DateAdd("m",-4,Date())"

DCX

would the <= work with that date Serial?
 
Data type mismatch

<=DateSerial(Year("Date"),Month("Date")-4,Day("Date"))

Ok i tried that but now i'm getting a Data Type Mismatch, would that be because of the bad field name or the fromat of the feild?
 
Functions, even if they have no arguments, need to have their brackets - otherwise the function is misinterpreted by Access in this situation as a typical piece of text.

<=DateSerial(Year(Date()),Month(Date())-4,Day(Date()))
 
now I'm stumped

well now i understand what was wrong and I tried it.

No datatype mismatch. but it still will not remove the Nov 1-11 entries. I know i've got at least 2 but the Query Appends 0 rows of data.

should the -4 be inside the () ex. "Month(Date()-4))"

or am I way off the mark?
 
Whoa. I go away for 15 minutes and there are 100 posts to this thread! :D

should the -4 be inside the () ex. "Month(Date()-4))"
No. The problem is one of mathematics. If this is February, and you remove four months, you get October. Change the 4 to a 3. Sorry I didn't see that before!
 
Duh

I should have seen that my self...:rolleyes:

I'm kicking my self

Thanks
 

Users who are viewing this thread

Back
Top Bottom