?
Solved

import ACCESS 2003 scripted objects

Posted on 2011-09-20
5
Medium Priority
?
272 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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

862 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