Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's an example from one of my programs (which still is in daily use at the company). It's taken from a vb6 program, but also executes in vba. I've tested it to be sure. </p> <p>In this example we have a temporary table with the name "mytable_tmp", which is updated with new data and we'd like to save this to the table "mytable" by replacing it.</p> <p>From your Excel vba editor you'll need to set a reference to the following two type libraries:</p> <ul> <li>"Microsoft ActiveX Data Objects 2.8 Library"</li> <li>"Microsoft ADO Ext. 2.8 for DDL and Security"</li> </ul> <p>The first one is for the ADODB namespace and the second for the ADOX namespace. (Maybe you have an earlier version of MDAC like 2.5 or earlier; this should work too).</p> <pre><code>Private Sub RenameTable() Dim cn As New ADODB.Connection Dim cat As ADOX.Catalog Const sDBFile As String = "c:\et\dbtest.mdb" On Error GoTo ErrH With cn .Provider = "Microsoft.Jet.OLEDB.4.0" .Mode = adModeShareDenyNone .Properties("User ID") = "admin" .Properties("Password") = "" .Open sDBFile End With Set cat = New ADOX.Catalog cat.ActiveConnection = cn cat.Tables("mytable").Name = "mytable_old" cat.Tables("mytable_tmp").Name = "mytable" cat.Tables("mytable_old").Name = "mytable_tmp" ExitHere: If Not cn Is Nothing Then If Not cn.State = adStateClosed Then cn.Close Set cn = Nothing End If Set cat = Nothing Exit Sub ErrH: Dim sMsg As String sMsg = "Massive problem over here man." sMsg = sMsg &amp; vbCrLf &amp; "Description : " &amp; cn.Errors.Item(0).Description MsgBox sMsg, vbExclamation GoTo ExitHere End Sub </code></pre> <p>Hoping to be helpful.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload