Due to a change in versions of Access by Users I am converting existing code from Data Access Objects (DAO) to conform to ActiveX Data Objects (ADO). All is working well except one thing which is twisting my brain.
I want to export all tables, a form, a macro and a module to a new database using VBA script. Here is the code...
The loop and transfer of the tables works fine, but message 2501: 'The TransferDatabase action was canceled' appears for the transfer of the form, module, or macro. Any ideas why and how to overcome this problem? Could it be something to do with the references? I have 6 checked...
Visual Basic for Applications,
Microsoft Access 9.0 Object Library,
OLE Automation,
Microsoft Visual Basic for Applications Extensibility 5.3,
Microsoft ActiveX Data Objects 2.1 Library, and
Microsoft ADO Ext. 2.7 for DDL and Security.
Thanks,
Softop
I want to export all tables, a form, a macro and a module to a new database using VBA script. Here is the code...
Code:
Private Sub cmdBackup_Click()
Dim rst As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim appPath As String
Dim tablename As String
Dim cat As New ADOX.Catalog
On Error GoTo FileErr
Code:
'Delete old database file if it exists
Code:
If Dir(txtPath.Value) <> "" Then
Kill txtPath.Value
End If
Code:
'Create a database in the defined path
Code:
cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & txtPath.Value & ";"
Code:
' Open the tables schema rowset
Code:
Set cnn = CurrentProject.Connection
Set rst = cnn.OpenSchema(adSchemaTables)
Code:
' Loop through the results and export the tables
Code:
Do Until rst.EOF
If rst.Fields("TABLE_TYPE") <> "VIEW" Then
tablename = rst.Fields("TABLE_NAME")
If Left(tablename, 4) <> "MSys" Then
Code:
DoCmd.TransferDatabase acExport, "Microsoft Access", & _
txtPath.Value, acTable, tablename, tablename
Code:
DoCmd.Close acTable, tablename
End If
End If
rst.MoveNext
Loop
Code:
'Export form, module, and macro
Code:
DoCmd.TransferDatabase acExport, "Microsoft Access", & _
txtPath.Value, acForm, "frmRestore", "frmRestore"
DoCmd.TransferDatabase acExport, "Microsoft Access", & _
txtPath.Value, acModule, "clsCommonDialog", "clsCommonDialog"
DoCmd.TransferDatabase acExport, "Microsoft Access", & _
txtPath.Value, acMacro, "buAutoExec", "AutoExec"
Code:
FileErr:
If Err.Number = 3044 Then
MsgBox "This pathname does not exist. Please enter a valid pathname."
Else
MsgBox Err.Number & ": " & Err.Description
End If
End Sub
The loop and transfer of the tables works fine, but message 2501: 'The TransferDatabase action was canceled' appears for the transfer of the form, module, or macro. Any ideas why and how to overcome this problem? Could it be something to do with the references? I have 6 checked...
Visual Basic for Applications,
Microsoft Access 9.0 Object Library,
OLE Automation,
Microsoft Visual Basic for Applications Extensibility 5.3,
Microsoft ActiveX Data Objects 2.1 Library, and
Microsoft ADO Ext. 2.7 for DDL and Security.
Thanks,
Softop