[AccessD] Save as Text

Gustav Brock Gustav at cactus.dk
Sun Dec 31 04:31:57 CST 2006


Hi Marty

It is slightly different. I know, because you wrote about it in July 2004 - as a method for creating a backup of tables, queries, and relations in a database file:

http://databaseadvisors.com/pipermail/accessd/2004-July/026305.html 

So the saved file is not a text file but a normal mdb file.

/gustav

>>> martyconnelly at shaw.ca 30-12-2006 22:15 >>>
Saving tables is the one exception to this method instead use the
DAP pages method, it is a carryover from the original Access 97 method
where it was really undocumented as opposed to just MS undocumented.
I got the original hint from Larry Lawson.

 'This saves all tables, references, relationships,
      ' DAP's and command menus to one file.

      SaveAsText acDataAccessPage, "", strPath & "dbAllTablesText.txt"

      'Save only once to one file so exit.
      '  the constant acDataAccessPage doesn't exist in Access 97
      ' so use the magic number 6

Also you may not want to save temp Queries so

    If  dbs.QueryDefs(i).Name, 1)  <> "~" Then
         'remove temp queries from selection


'using acTable = 0   with SaveAsText 'Tables won't work in 2003 or 97
   ' you will get saveastext 2487 error.


Martin Reid wrote:

>Just fixing some stuff up. ANyone any idea whats the problem with this. It fails as soon as it tried to export the tables.
> 
>Martin
> 
> 
> 
>Public Sub createtemplate()
>    
>    Dim db As Database
>    Dim doc As Document
>    Dim conn As Container
>    Dim strPath As String
>    Dim I As Integer
>    Set db = CurrentDb()
>    strPath = "C:\forms\"
>    'Export the forms
>    Set conn = db.Containers("Forms")
>    For Each doc In conn.Documents
>        Application.SaveAsText acForm, doc.Name, strPath & "Form_" & doc.Name & ".txt "
>    Next doc
>    'Export the Rreports
>    Set conn = db.Containers("Reports")
>    For Each doc In conn.Documents
>        Application.SaveAsText acReport, doc.Name, strPath & "Report_" & doc.Name & ".txt"
>    Next doc
>    Set conn = db.Containers("Modules")
>    For Each doc In conn.Documents
>        Application.SaveAsText acModule, doc.Name, strPath & "Module_" & doc.Name & ".txt"
>    Next doc
>For Each td In db.TableDefs
>    If Left(td.Name, 4) <> "MSys" Then
>    DoCmd.TransferText , acExportDelim, , tb.Name, strPath & "Table " & td.Name & "text", True
>    End If
>Next td
>For I = 0 To dbs.QueryDefs.Count - 1
>    Application.SaveAsText acQuery, dbs.QueryDefs(I).Name, "strPath" & dbs.QueryDefs(I).Name & ".txt"
>Next I
>
>    Set db = Nothing
>    Set conn = Nothing
>    Set doc = Nothing
>Exit_createtemplate:
>    Exit Sub
>    
>End Sub
> 
>Martin WP Reid
>Training and Assessment Unit
>Riddle Hall
>Belfast
> 
>tel: 02890 974477




More information about the AccessD mailing list