(Msg. 1) Posted: Fri Jul 04, 2008 3:09 am
Post subject: Delete data more than 2 months old Add to elertz Archived from groups: microsoft>public>access (more info?)
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.
(Msg. 2) Posted: Fri Jul 04, 2008 3:37 am
Post subject: RE: Delete data more than 2 months old Add to elertz [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
Oops sorry, the criteria should be <Now()
"AJCB" wrote:
> 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
(Msg. 3) Posted: Fri Jul 04, 2008 3:37 am
Post subject: RE: Delete data more than 2 months old Add to elertz [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
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
"AJCB" wrote:
> 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
(Msg. 4) Posted: Fri Jul 04, 2008 4:07 am
Post subject: RE: Delete data more than 2 months old Add to elertz [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
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" wrote:
> 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
>
> "AJCB" wrote:
>
> > 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
(Msg. 5) Posted: Fri Jul 04, 2008 4:28 am
Post subject: RE: Delete data more than 2 months old Add to elertz [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
It works OK but obviously I cannot see what you have done. Have you tried it
Allen's way instead ?
"AJCB" wrote:
> 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" wrote:
>
> > 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
> >
> > "AJCB" wrote:
> >
> > > 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
(Msg. 6) Posted: Fri Jul 04, 2008 4:44 am
Post subject: RE: Delete data more than 2 months old Add to elertz [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
I will try, but I am not really that confident using SQL queries, as I
usually cannot get them to work.
"Dennis" wrote:
> It works OK but obviously I cannot see what you have done. Have you tried it
> Allen's way instead ?
>
> "AJCB" wrote:
>
> > 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" wrote:
> >
> > > 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
> > >
> > > "AJCB" wrote:
> > >
> > > > 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
(Msg. 7) Posted: Fri Jul 04, 2008 3:42 pm
Post subject: Re: Delete data more than 2 months old Add to elertz [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
>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.
--
(Msg. 8) Posted: Fri Jul 04, 2008 6:30 pm
Post subject: Re: Delete data more than 2 months old Add to elertz [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
DELETE FROM [YourTableNameHere]
WHERE [YourDateTimeFieldHere] < DateAdd("m", -2, Date());
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"AJCB" <AJCB.DeleteThis@discussions.microsoft.com> wrote in message
news:7B61CF07-A879-4EF6-8AD2-1EFD317214E2@microsoft.com...
> 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
All times are: Eastern Time (US & Canada) (change)
Page 1 of 1
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum