Solved

import ACCESS 2003 scripted objects

Posted on 2011-09-20
5
242 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:ssmith94015
  • 3
  • 2
5 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 36567706
use, something like this

Application.LoadFromText acForm, "XMain", "E:\main.txt"
0
 

Author Comment

by:ssmith94015
ID: 36567736
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.
0
 

Author Closing Comment

by:ssmith94015
ID: 36567769
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
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 36567774
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
0
 

Author Comment

by:ssmith94015
ID: 36567793
Thanks, that will work even better.  
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now