Max Wanadoo
max.wanadoo at gmail.com
Sat Feb 13 20:25:54 CST 2010
Hi Shamil, Just done some more coding to create a NEW DB and populate with objects from OLD DB without having to open either of them. Assuming you are sitting in DB1 (code below) and you want to take all the objects from Existing DB2 and create a Brand New DB3, here is one way (code below) To keep the idea simply, I have opened DB1 and run sExportRemoteObjectsAsText() which exported all the Forms from DB2. (The actual export code would be replaced by the code you are creating/posting now to export ALL objects. This is just a demo bit to keep it short.) Then once the objects have been exported as textfiles, I run the code in sImportRemoteObectsFromTextIntoNewDB() which imports the text objects into DB3. (Again, to keep the example simple, I have just imported one object but this would be replaced by your code to bring all objects back) If you now look at the NEW DB3 you will see ALL the objects that are sitting in DB2 copied into a brand new database DB3 with no bloat etc. DB2 remains unharmed or altered in anyway. With this code you have done all this automatically without opening either DB2 or DB3. Would this be a useful wrapper to your project code? I think this would work with ADP projects too but not sure. Max (Watch for wrap) CODE for DB1. Option Compare Database Option Explicit Private dbsNew As DAO.Database Private wrkDefault As Workspace Private proj As CurrentProject Private obj As Object Private appAccess As New Access.Application Sub sExportRemoteObjectsAsText() appAccess.OpenCurrentDatabase "C:\_MCM\DB2.mdb", False Set proj = appAccess.CurrentProject For Each obj In proj.AllForms ' export form objects just as an example appAccess.SaveAsText acForm, obj.Name, "C:\_MCM\Objects\" & obj.Name & ".txt" Next obj appAccess.CloseCurrentDatabase ' shut down temp application End Sub Sub sImportRemoteObectsFromTextIntoNewDB() Set wrkDefault = DBEngine.Workspaces(0) ' Get default Workspace. If Dir("C:\_MCM\DB3.mdb") <> "" Then Kill "C:\_MCM\DB3.mdb" ' Make sure there isn't already a file with the name of the new database. Set dbsNew = wrkDefault.CreateDatabase("C:\_MCM\DB3.mdb", dbLangGeneral) ' Create a new un-encrypted database with the specified collating order. dbsNew.Close Set dbsNew = Nothing appAccess.OpenCurrentDatabase "C:\_MCM\DB3.mdb", False ' set a reference to it appAccess.LoadFromText acForm, "Form1", "C:\_MCM\Objects\Form1.txt" ' load a sample object into it. appAccess.CloseCurrentDatabase ' shut down temp application End Sub