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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not in this collection 2

Status
Not open for further replies.

lars7

Technical User
Aug 16, 2005
817
GB
Hi Guys,

I'm trying to change the names of 3 tables with the following code but I'm getting this error message "Item not found in this collection"

Option Compare Database
Option Explicit

Function RenameTables()
Dim db As DAO.Database


Set db = CurrentDb
Debug.Print
db.TableDefs("EmpDep_Old").Name = "Empdep_Archive"
db.TableDefs("EmpDep_New").Name = "Empdep_Old"
db.TableDefs("EmpDep_New_Temp").Name = "Empdep_New"

Set db = Nothing

End Function

I think I have the correct references ticked so I'm not sure where I've gone wrong.

Thanks in advance.
 
One of the names of your tabledefs obviously spelled wrong.
 
and the hghlighted line will prolly indicate which one :)

JB
 
A crude way to solve your issue:
Code:
Function RenameTables()
Dim db As DAO.Database
Set db = CurrentDb
[!]On Error Resume Next[/!]
db.TableDefs("EmpDep_Old").Name = "Empdep_Archive"
db.TableDefs("EmpDep_New").Name = "Empdep_Old"
db.TableDefs("EmpDep_New_Temp").Name = "Empdep_New"
Set db = Nothing
End Function

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV!

Crude aint the word! How dare you condone such things?! lol.

JB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top