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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying the names of all of the modules in the database 2

Status
Not open for further replies.

ddiamond

Programmer
Apr 22, 2005
918
US
I have the following code:
Code:
Public Sub test()
  Dim Mods As Modules
  Dim Mod1 As Module
  
  Set Mods = Application.Modules
  
  For Each Mod1 In Mods
    Debug.Print Mod1.Name
  Next
  
End Sub

Can anyone tell me why this only lists one module instead of all of them?
 
Application.Modules contains all open standard modules and class modules in a Microsoft Access database.

Use CurrentProject.AllModules to get a list.

Code:
For Each mdl In CurrentProject.AllModules 
  Debug.Print mdl.Name
Next

 
Thanks Remou. Access 97 does not have the CurrentProject object. Does anyone know how to do this in Access 97?
 
Thanks Remou. Their code snipet worked.
Code:
'List modules
Sub ListMods()
  Dim db As Database
  Dim ModuleN As Document
  
  Set db = CurrentDb
  For Each ModuleN In db.Containers!Modules.Documents
    Debug.Print ModuleN.Name
  Next ModuleN
End Sub
 
What I really want to do is display the code behind each module. I believe the module object contains this information, but the document object does not. Now if all of the modules were open, then the application.modules collection would work. Is there anyway with VBA to open all of the closed modules?
 
Here's my final code.
Code:
Sub ListMods()
  Dim db As Database
  Dim ModDoc As Document
  Dim ModN As Module
  
  Set db = CurrentDb
  For Each ModDoc In db.Containers!Modules.Documents
    DoCmd.OpenModule ModDoc.Name
  Next
  
  For Each ModN In Modules
    Debug.Print ""
    Debug.Print "Module " & ModN.Name
    Debug.Print ModN.Lines(1, ModN.CountOfLines)
  Next
  
End Sub
 
It looks like a similar approach can be taken with forms and reports. Does anyone know if something like this is possible with macros?
 
Did you miss this bit in Joshua J. Kugler's post:

Code:
'List macros 
Sub ListMac() 
Set db = CurrentDb 
For Each MacroN In db.Containers!Scripts.Documents 
Debug.Print MacroN.Name 
Next MacroN 
End Sub

Or had you something fancier in mind?

 
That lists the macro names. My real goal is to write a search and replace. I was foolish enough to hard code the path in many-many transfertext macros. Now I need to change the path, and I am hoping I won't have to do it by hand.
 

Just to mention this query

SELECT [Name]
FROM MSysObjects
WHERE Type=-32761

and the undocumented Application.SaveAsText method along with
Application.LoadFromText with the most recent thread705-1175611
 
Thanks Jerry. I'll give it a try. In theory I could save it to text files, then do my search and replace, then reload them using the LoadAsText method. Sounds a bit risky, but that is what testing is for.
 
ddiamond

Well, right now I 'm doing exactly what you described to be "theory". Aint we having fun, or what?
 
Jerry,

Can you post the code you used to load the macros back in?

- Dan
 

LoadFromText acMacro,"YourMacroName", "c:\path\SavedMacroName.xcs"

LoadFromText acModule, "YourModuleName", "c:\path\SavedModuleName.xcm"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top