Microsoft KB Archive/291017

= How To Change an Access Table Name Programmatically =

Article ID: 291017

Article Last Modified on 6/29/2004

-

APPLIES TO


 * 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 6.0 Enterprise Edition
 * 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

-



This article was previously published under Q291017



SUMMARY
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.



MORE INFORMATION
To use a Visual Basic 6.0 project to change an Access table name programmatically by using ADOX, do the following:  Open a new Standard EXE project in Visual Basic. Form1 is created by default. 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'''.  Paste the following code into the form load event: Dim cn As ADODB.Connection Dim t As Table

Set cn = New ADODB.Connection cn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;data Source=C:\biblio.mdb&quot; Dim cat As ADOX.Catalog Set cat = New ADOX.Catalog Set cat.ActiveConnection = cn cat.Tables(&quot;Authors&quot;).Name = &quot;Authors2&quot;

'Iterate through the tables collection For Each t In cat.Tables If t.Name = &quot;Authors2&quot; Then Debug.Print t.DateModified End If Next

cn.Close Set cn = Nothing  Save and execute the Visual Basic project, and note that the Immediate window displays the DateModified property value of the &quot;Authors2&quot; table, which is equal to the current day's date.

Keywords: kbhowto KB291017

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.