How To Change an Access Table Name Programmatically

This article was previously published under Q291017
This article has been archived. It is offered "as is" and will no longer be updated.
There are several ways to change a Microsoft Access table name in a Visual Basic application, some of which include the use of SQL, OLE automation, or Microsoft ActiveX Data Objects Extensions for Data Definition Language and Security (ADOX).The simplest method is to use ADOX to rename a table.
To use a Visual Basic 6.0 project to change an Access table name programmatically by using ADOX, do the following:
  1. Open a new Standard EXE project in Visual Basic. Form1 is created by default.
  2. On the Project menu, click to select References, and then add references to Microsoft ActiveX data object 2.x library and Microsoft ADO Ext. 2.x for DDL and Security.
  3. Paste the following code into the form load event:
    Dim cn As ADODB.ConnectionDim t As TableSet cn = New ADODB.Connectioncn.Open "Provider=Microsoft.Jet.OLEDB.4.0;data Source=C:\biblio.mdb"Dim cat As ADOX.CatalogSet cat = New ADOX.CatalogSet cat.ActiveConnection = cncat.Tables("Authors").Name = "Authors2"'Iterate through the tables collectionFor Each t In cat.Tables  If t.Name = "Authors2" Then    Debug.Print t.DateModified  End IfNextcn.CloseSet cn = Nothing					
  4. Save and execute the Visual Basic project, and note that the Immediate window displays the DateModified property value of the "Authors2" table, which is equal to the current day's date.

Article ID: 291017 - Last Review: 12/06/2015 01:01:57 - Revision: 4.2

Microsoft Data Access Components 2.0, Microsoft Data Access Components 2.1, Microsoft Data Access Components 2.5, Microsoft Data Access Components 2.6, Microsoft Visual Basic 5.0 Professional Edition, Microsoft Visual Basic 6.0 Professional Edition, Microsoft Visual Basic 5.0 Enterprise Edition, Microsoft Visual Basic Enterprise Edition for Windows 6.0, Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 3, Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 4, Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 5

  • kbnosurvey kbarchive kbhowto KB291017