Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rename Table - Append Month 2 months previous to title 2

Status
Not open for further replies.

dominicdunmow

Technical User
Jul 28, 2004
125
0
0
CA
Hi there,

I have a table that I'd like to archive, in order to do so I'm renaming it and adding appending the month in which it applies to. The code below adds the current month, but I'd like to add 2 months previous, e.g Format(Date, "MMM" - 2)
but I can't work out the code.

DoCmd.Rename "tblArchiveOSP_" & Format(Date, "MMM"), acTable, "tblOSPPrevious"

Can anyone point me in the right direction please.

Thanks
 


Hi,

The YEAR is not important? So this year's Sep table will go bye bye when Oct 2006 rolls around?
Code:
DoCmd.Rename "tblArchiveOSP_" & Format(DateSerial(Year(Date),Month(Date)+1,1), "MMM"), acTable, "tblOSPPrevious"


Skip,
[sub]
[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue][/sub]
 
DoCmd.Rename "tblArchiveOSP_" & Format(DateAdd("m",-2,Date), "MMM"), acTable, "tblOSPPrevious"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for your responses.

The database is a temporary solution so in theory year doesn't matter but for best practice's sake I've included - thanks for the nudge.

DoCmd.Rename "tblArchiveOSP_" & Format(DateAdd("m", -2, Date), "MMM") & Format(Date, " yyyy"), acTable, "tblOSPPrevious"

Dominic
 


For collating purposed, I'd format the YEAR first...
[tt]
Format(DateAdd("m", -2, Date), "yyyymmm")
[/tt]


Skip,
[sub]
[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top