dynamic table name

aftershokk

Registered User.
Local time
Today, 22:57
Joined
Sep 5, 2001
Messages
259
Hi all, I am not that good with VBA but I am trying.

I want to make a backup copy of a table every month using a macro that inserts the current date and time into the name of the table. I tried using copy object as shown below but it just pastes the name as written?

Function Macro1()
On Error GoTo Macro1_Err

DoCmd.CopyObject "", "test & Date", acTable, "monthly_table"


Macro1_Exit:
Exit Function

Macro1_Err:
MsgBox Error$
Resume Macro1_Exit

End Function
 
Try

DoCmd.CopyObject "", "test" & Date(), acTable, "monthly_table"
 
Change this part:

"test & Date"

to this:

"test" & Date


But I wouldn't leave slashes in the object names, so I would reduce it to this before doing it:

"test" & Year(date) & Month(Date) & Day(Date)
 
Good point Bob. You could also use:

Format(Date(), "yyyymmdd")

or whatever format you want.
 
as always

This forum is my life saver! Thanks to all!

I actually had something like Bob's originally but I messed up the quotes (which I always do!)

thanks!!!
 
This forum is my life saver! Thanks to all!

I actually had something like Bob's originally but I messed up the quotes (which I always do!)

thanks!!!

Just as a reminder - for future reference - if you have variables or references to other objects, they need to be outside of the quotes. If you want something literally to be there, then you put it inside the quotes.
 

Users who are viewing this thread

Back
Top Bottom