Object Export Problem

  • Thread starter Thread starter BobEQ
  • Start date Start date
B

BobEQ

Guest
I'm using the Application.SaveAsText Method to export the objects in an Access database and it works great. I'm using the code below.

My problem arises when I try to make the application more flexible so I can pass in a different database name - using the sSourceDB variable. And basically if I don't set db=CurrentDB I get an error (2001 - You canceled the previous operation).

I can't find anything that says you have to use currentdb, but it seems you do.

If anyone knows of a solution to fix this problem please let me know.

thanks,
Bob


---------------------------------------------------------------------
Sample Below
---------------------------------------------------------------------
Public Sub ExportDatabaseObjects(sSourceDB As String, sExportLocation As String)
On Error GoTo Err_ExportDatabaseObjects

Dim db As Database
Dim td As TableDef
Dim d As Document
Dim c As Container
Dim i As Integer

'Set db = CurrentDb
Set db = DBEngine.OpenDatabase(sSourceDB)

Set c = db.Containers("Forms")
For Each d In c.Documents
'The following line generates 2001 - You canceled the previous operation when db is not equal to CurrentDB
Application.SaveAsText acForm, d.Name, sExportLocation & "Form_" & d.Name & ".txt"
Next d

Set c = db.Containers("Reports")
For Each d In c.Documents
Application.SaveAsText acReport, d.Name, sExportLocation & "Report_" & d.Name & ".txt"
Next d

Set c = db.Containers("Scripts")
For Each d In c.Documents
Application.SaveAsText acMacro, d.Name, sExportLocation & "Macro_" & d.Name & ".txt"
Next d

Set c = db.Containers("Modules")
For Each d In c.Documents
Application.SaveAsText acModule, d.Name, sExportLocation & "Module_" & d.Name & ".txt"
Next d

For i = 0 To db.QueryDefs.Count - 1
Application.SaveAsText acQuery, db.QueryDefs(i).Name, sExportLocation & "Query_" & db.QueryDefs(i).Name & ".txt"
Next i

Set db = Nothing
Set c = Nothing

MsgBox "All database objects have been exported as a text file to " & sExportLocation, vbInformation

Exit_ExportDatabaseObjects:
Exit Sub
Err_ExportDatabaseObjects:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_ExportDatabaseObjects
End Sub
 
Shouldnt you just send the path?
does sSourceDB contain "C:\MyDB.MDB"

instead of

Set db = DBEngine.OpenDatabase(sSourceDB)

use

Set db = "C:\MyDB.MDB"
 
yes, sSourceDB is a sting containing the path to a access database.

If I use " set db = sSourceDB " then I get a type mismatch error because I'm setting a database type object to a string value.
 
Sorry bout that -

This worked for me

Set db = OpenDatabase("c:\MyDB.MDB")
 
I get the same error when I do that.

2001 - You canceled the previous operation.

right when it hits this line of code.
Application.SaveAsText acForm, d.Name, sExportLocation & "Form_" & d.Name & ".txt"


this is really frustrating, especially now that I know it's working for someone else.

thanks anyway.
 

Users who are viewing this thread

Back
Top Bottom