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

Count Lines of VBA Code 2

Status
Not open for further replies.

maxhugen

Programmer
May 25, 2004
498
AU
I did see some code yonks ago that counted the lines of code for every module (incl form and report modules), and output a file that looked something like:

[tt]LINES PER MODULE
Form_myForm1 82
Form_myForm2 0
Form_myForm3 123
Report_myReport1 18
Report_myReport2 0
Report_myReport3 0
Module1 546
Module2 231
Module3 408[/tt]

Would anyone have some code to do that, or point me to a relevant URL, as I can't find that code snippet again.

MTIA


Max Hugen
Australia
 
A starting point:
For Each objVBC In Application.VBE.ActiveVBProject.VBComponents
Debug.Print objVBC.Name, objVBC.CodeModule.CountOfLines
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You may wish to look at:

thread705-1386464

Which includes suggestions for form code.
 
Thanks PHV, Remou

Using the ActiveVBProject is ideal for A2000 and beyond. For A97 mdbs, I'll see if I can mod Remou's suggestion.

Cheers

Max Hugen
Australia
 
Still having a prob trying to do this for an A97 mdb. I'm trying to loop through the forms collection, but get error 3251: Operation is not supported for this type of object.

I must have something wrong with the way I'm trying to enumerate the objects in the container?
Code:
Dim db As Database: Set db = CurrentDb
Dim cont As Container, doc As Document
    Set cont = db.Containers!Forms
    [red]For Each doc In cont[/red]     [green]' error here[/green]
        DoCmd.OpenForm doc.name, acDesign, , , , acHidden
        cnt = IIf(Forms(doc.name).HasModule, _
                  Forms(doc.name).Module.CountOfLines, _
                  0)
        Debug.Print doc.name, cnt
    Next doc
Any suggestions, pls?

Max Hugen
Australia
 
All good, found the error:
Code:
Dim db As Database: Set db = CurrentDb
Dim cont As Container, doc As Document
    Set cont = db.Containers!Forms
    For Each doc In cont[blue].Documents[/blue]
        DoCmd.OpenForm doc.name, acDesign, , , , acHidden
        cnt = IIf(Forms(doc.name).HasModule, _
                  Forms(doc.name).Module.CountOfLines, _
                  0)
        Debug.Print doc.name, cnt
    Next doc

Max Hugen
Australia
 
alas, this subject arises every so often. the actual code is quite straightforward, the rationale for wanting to do the exercise is often not and -at least in my experience- never satisfactory.

would someone please explain to me what useful purpose is involved here?




MichaelRed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top