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

rename a table in another database 1

Status
Not open for further replies.

pkw

Technical User
May 15, 2001
3
US
At the close of each accounting period, I would like to rename the current month table to a prior month table and then create the new month's table. The tables exist in another database and are fairly large so I prefer to rename vs. copy. This is the direction I am going but am not much of a VBA programmer. Any help will be appreciated!
Dim dbcurrent As Database
Set dbcurrent = CurrentDb()
Dim dbmthly As DAO.Database
Dim ws As DAO.Workspace
Dim rst As Recordset
Dim prevperiod As Variant
Set rst = dbcurrent.OpenRecordset("endofmth")
If rst![PeriodEnd] = "Yes" Then
Set prevperiod = rst![priorperiod]
Set ws = DBEngine.Workspaces(0)
Set dbmthly = ws.OpenDatabase("r:\pra\reporting\sales channel.mdb")
dbcurrent.Close
DoCmd.Rename "SalesChannel_Monthly" & "_"&"prevperiod", acTable, "SalesChannel_Monthly"
End If
 
Hi!

It's easy:

Sub TableRename()
Dim dbs As Database
Dim tdf As TableDef

Set dbs = DBEngine.Workspaces(0).OpenDatabase("C:\TEMP\db1.mdb")
Set tdf = dbs.TableDefs("OldTableName")
tdf.Name = "NewTableName"
dbs.Close
End Sub

Aivars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top