Link to home
Start Free TrialLog in
Avatar of Sandra Smith
Sandra SmithFlag for United States of America

asked on

import ACCESS 2003 scripted objects

Ok, I have a mdoule that exports all the Access 2003 objects and I am happy with that.  I had created a recovery database with teh code to bring all the objects into a blank data - however, to be honest, I can't find it!  Does anyone know teh simple code to bring in all the object that have been exported to text files by the attached code.  This code is fine, I just need the code to bring it into a new, blank database.
On Error GoTo Err_ExportDatabaseObjects
Dim db As DAO.Database
Dim td As DAO.TableDef
Dim d As Document
Dim C As Container
Dim i As Integer
    
    Set db = CurrentDb()
     
    For Each td In db.TableDefs 'Tables
        If Left(td.Name, 4) <> "MSys" Then
           DoCmd.TransferText acExportDelim, , td.Name, sExportLocation & "Table_" & td.Name & ".txt", True
       End If
   Next td
    
    Set C = db.Containers("Forms")
    For Each d In C.Documents
        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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sandra Smith

ASKER

Cap, I thought it would be you!  I think to answered this question many years ago, I just can't find that question/answer.  Let me try and I will be right back.
Yes, this was it.  I am going to assume that for each object type, module, report, form, query, I would simply replace the acForm with the correct constant.

Sandra
you can iterate all .txt file in the folder with

dim txtPath,txtFile
txtpath="c:\myfolder\"

txtfile=dir(txtPath & "*.txt")

while txtFile <>""
   select case left(txtfile,instr(txtFile,"_")-1)
         case "Form"

         case "Table"

         'etc...
   end select
Thanks, that will work even better.