Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to combine Containers and Access Modules Collections

Status
Not open for further replies.

fburges

Programmer
Apr 18, 2005
6
0
0
US
Hi anyone
I'm new to tek-tips, & have a puzzler. With code in a source db in Access 2002 I want to open a target db's Access Modules collection, iterate each module by name, and use the Lines property of the Modules collection to copy the module's code to a table in the source db. Problem is that I only know how to get at the Modules collection for the current db, not the target db. How do I get at the target db's Modules collection? PS: I don't use the AllModules collection because OpenCurrentDatabase actually opens the db, which triggers start ups. I apologize for my wordiness. Anyone know of a way?
The following code is written in source.mdb.
Dim db As Database
Dim doc As Document
Set db = OpenDatabase("c:\temp\target.mdb")
For Each doc In db.Containers("Modules").Documents
MsgBox doc.Name

'WHAT HAPPENS NEXT - How to select target.mdb Module
'objects and use Lines property to copy the code to
'source.mdb?
Next
 
In case anyone is interested, I've figured out what to do myself. Since the solution caused me so much headache, I thought I'd post it. My original intention was to copy each line of text from each module in the target db into a table in my current db for the purpose of documenting (allow me to search through them all at once without having to open each db separately) the modules in all my other dbs. Further, I do not intend to edit the modules. I simply want to document the text so I can search through it programmatically. (I am building a database documenter so I can do a Find command thru the code in all my databases to find something nifty I might have done somewhere else.) This proved impossible due to startups getting in the way, and other problems. So instead of copying each line of text out of the target db, I simply do a TransferDatabase once for each module in the target db! TransferDabase does not open the target db (it just creates pointers to the objects in it), so no startups. In this way, I can simply import all the target db's modules into my own db without startups getting in the way. After the code I created runs, I will have the target module's text in a table in my source db, and can include it in my documenter, which allows me to search thru it for "neat stuff" and how I did it. That's the easy part. It was getting the text over that gave me a headache.

Dim db As Database
Dim doc As Document
Dim strdbname As String
strdbname = "c:\temp\target.mdb"
Set db = DBEngine.Workspaces(0).OpenDatabase(strdbname)
For Each doc In db.Containers("Modules").Documents
' In case you want to see the module's name
MsgBox doc.Name
' The real heart of the program
DoCmd.TransferDatabase acImport, "Microsoft Access",_ strdbname, acModule, doc.Name, "targetTable"
Next
This code represents the bare bones of it all, and will be sandwiched with other code to handle the database selections, module selections, editing, and other massaging of the imported data, but the core engine is here. The "_" at end of the TransferDabase method is just to show a line continuation and can be ignored if you use it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top