Rename Table With Code

  • Thread starter Thread starter Bonnie
  • Start date Start date
B

Bonnie

Hi there. Using A02 on XP. Asked some time ago how to
rename a table during an event procedure on a button click.
Mr Steele gave me the info below but I got an error and
couldn't move past it. I didn't get a followup response so
I'm reposting in hopes to finish this up.

From Mr. Steele:
CurrentDb().TableDefs("PayPerData").Name = "PayPerData" & Format$(Date,
"mmddyyyy")

I can't remember whether you need a reference to DAO to make this work in
Access 2000 and 2002.

Original Inquiry:
Hi there and thanks for the info. Placed wordage on a form
button's OnClick Event but getting Runtime Error 3265 -
Item not found in this collection. Mine reads:

CurrentDb().TableDefs("AmerHlthPayPeriodData").Name
= "AmerHlthPayPeriodData" & Format$(Date, "mmddyy")

I checked my references and DAO 3.6 is in my Tools,
References list. Do I have to put any additional wordage
in my code to define the item? Kinda new at event
procedure code but loving it so hoping to hear from
someone. Thanks for any additional help or advice you can
provide!
 
Bonnie

Try

Docmd.Rename "NewTableName",acTable,"OldTableName"

Simple Access command, no fuss no muss.

Ron W
 
You are a sweatheart!!! To be sure, less is best! Thank
you very, very much for the prompt reply!
 
Dan, I appreciate the info. I'll try to remember to
explore a bit better in the macros in future.

Thanks again!
 
Back
Top