0

So i have the following query:

DoCmd.RunSQL "delete * from [TABLE NAME] where month = '" & Format(PrevMonth, "yyyy-mm-dd") & "'"

month is a Text field.

Lets say PrevMonth = August 2010 so instead of delete the rows where the date is august 2010, i want it to delete august 2010 and all after that? so september 2010, october 2010, and so on.

thanks.

0

2 Answers 2

2

You can use the CDate() function to cast your text date to date/time data type.

Then:

DELETE FROM [TABLE NAME]
WHERE CDate([month]) >= #2010/08/01#;

I enclosed the field name in brackets because Month() is an Access VBA function ... the brackets let Access know to treat month as a field rather than the function. If it were my database, I would rename the field.

Sign up to request clarification or add additional context in comments.

Comments

1

First create a query based on [TABLE Name] where you convert month from text to date
SELECT *,CDate("1 " & [Month]) AS DateDate
FROM Table Name;
Now you can use the dates as normal
DELETE Query1.DateDate
FROM Query1
WHERE (((Query1.DateDate) Between #1/1/2010# And #12/31/2010#));

Hope this helps

2 Comments

HansUp version will in one statement, but if CDate fails for any record, my version will allow it easier to check what is going on
Thanks, i gave you a vote but its not what I am looking for. I am just an intern here and they have me managing an access program with full of spaghetti code programmed by another student. So adding this would further complicate things for the next guy coming in to maintain this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.