Delete Query not working.

G

Guest

The following query hangs up on me. I need it to remove records 5 days old.

DELETE [T: Cust Code Backup].Date
FROM [T: Cust Code Backup]
WHERE ((([T: Cust Code Backup].Date)<DateAdd("d",-5,Date())));

DELETE [T: Cust Code Backup].*
FROM [T: Cust Code Backup]
WHERE ((([T: Cust Code Backup].Date)<DateAdd("d",-5,Date())));

DELETE [T: Cust Code Backup].*
FROM [T: Cust Code Backup]
WHERE ((([T: Cust Code Backup].Date)<Date()-5));

I have tried it a lot of ways and it still hangs up.

Can someone help me out.

The table needs all records related to the date deleted. The table also has
3 key fields including the date field.
 
G

Guest

This one works for me:

DELETE [T: Cust Code Backup].*, [T: Cust Code Backup].Date
FROM [T: Cust Code Backup]
WHERE ((([T: Cust Code Backup].Date)<Date()));

However this is on a table with no relationships to other tables. Is your
table related to any other tables in the relationship window? If so is
cascade delete on?

Also you have a field named "Date" which is a reserved word in Access. In
fact you can see why as you are using the Date function in your queries. Try
putting some square brackets around the Date field.

Are you receiving an error message or does the query just doesn't seem to
stop. Are the records being deleted? Maybe someone set warnings off without
turning them back on in code or a macro. In this case the query might be
running just fine and just not warning you about the deleting the records.
 
G

Guest

After I changed the field name it seems to work better and faster. Is there
a list of "restricted" words that I can get a hold of so I do not do this
again?
--
Thank you for your time.
Windows XP
Office 2002


Jerry Whittle said:
This one works for me:

DELETE [T: Cust Code Backup].*, [T: Cust Code Backup].Date
FROM [T: Cust Code Backup]
WHERE ((([T: Cust Code Backup].Date)<Date()));

However this is on a table with no relationships to other tables. Is your
table related to any other tables in the relationship window? If so is
cascade delete on?

Also you have a field named "Date" which is a reserved word in Access. In
fact you can see why as you are using the Date function in your queries. Try
putting some square brackets around the Date field.

Are you receiving an error message or does the query just doesn't seem to
stop. Are the records being deleted? Maybe someone set warnings off without
turning them back on in code or a macro. In this case the query might be
running just fine and just not warning you about the deleting the records.

--
Jerry Whittle
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


James Kendall said:
The following query hangs up on me. I need it to remove records 5 days old.

DELETE [T: Cust Code Backup].Date
FROM [T: Cust Code Backup]
WHERE ((([T: Cust Code Backup].Date)<DateAdd("d",-5,Date())));

DELETE [T: Cust Code Backup].*
FROM [T: Cust Code Backup]
WHERE ((([T: Cust Code Backup].Date)<DateAdd("d",-5,Date())));

DELETE [T: Cust Code Backup].*
FROM [T: Cust Code Backup]
WHERE ((([T: Cust Code Backup].Date)<Date()-5));

I have tried it a lot of ways and it still hangs up.

Can someone help me out.

The table needs all records related to the date deleted. The table also has
3 key fields including the date field.
 
G

Guest

Right here:

http://support.microsoft.com/kb/286335/

Sure is a lot of them. Basically if it's a function, it's a reserved word.
Some are very common words such as Date, Year, Month, and Order.
--
Jerry Whittle
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


James Kendall said:
After I changed the field name it seems to work better and faster. Is there
a list of "restricted" words that I can get a hold of so I do not do this
again?
--
Thank you for your time.
Windows XP
Office 2002


Jerry Whittle said:
This one works for me:

DELETE [T: Cust Code Backup].*, [T: Cust Code Backup].Date
FROM [T: Cust Code Backup]
WHERE ((([T: Cust Code Backup].Date)<Date()));

However this is on a table with no relationships to other tables. Is your
table related to any other tables in the relationship window? If so is
cascade delete on?

Also you have a field named "Date" which is a reserved word in Access. In
fact you can see why as you are using the Date function in your queries. Try
putting some square brackets around the Date field.

Are you receiving an error message or does the query just doesn't seem to
stop. Are the records being deleted? Maybe someone set warnings off without
turning them back on in code or a macro. In this case the query might be
running just fine and just not warning you about the deleting the records.

--
Jerry Whittle
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


James Kendall said:
The following query hangs up on me. I need it to remove records 5 days old.

DELETE [T: Cust Code Backup].Date
FROM [T: Cust Code Backup]
WHERE ((([T: Cust Code Backup].Date)<DateAdd("d",-5,Date())));

DELETE [T: Cust Code Backup].*
FROM [T: Cust Code Backup]
WHERE ((([T: Cust Code Backup].Date)<DateAdd("d",-5,Date())));

DELETE [T: Cust Code Backup].*
FROM [T: Cust Code Backup]
WHERE ((([T: Cust Code Backup].Date)<Date()-5));

I have tried it a lot of ways and it still hangs up.

Can someone help me out.

The table needs all records related to the date deleted. The table also has
3 key fields including the date field.
 

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