PC Review


Reply
Thread Tools Rate Thread

Count Module Lines

 
 
Ron Carr
Guest
Posts: n/a
 
      14th Sep 2003
I have a databse which reviews other databases and counts objects.
I would also like to count the lines of code in Modules and forms in the
other databases, but cannot make the connection to do so.
I am aware of the properties that yiend the module line count, it is a
matter of connecting to the module / Form.
Thanks for any help!


 
Reply With Quote
 
 
 
 
Marshall Barton
Guest
Posts: n/a
 
      14th Sep 2003
Ron Carr wrote:

>I have a databse which reviews other databases and counts objects.
>I would also like to count the lines of code in Modules and forms in the
>other databases, but cannot make the connection to do so.
>I am aware of the properties that yiend the module line count, it is a
>matter of connecting to the module / Form.


You have to open an object before you can use its
properties:

' Count lines of code in Modules
For Each doc In dbother.Containers("Modules").Documents
DoCmd.OpenModule doc.Name
With Modules(doc.Name)
Debug.Print .Name, .CountOfLines
End With
DoCmd.Close acModule, doc.Name, acSaveNo
Next doc
' Count lines of code in Forms
For Each doc In dbother.Containers("Forms").Documents
DoCmd.OpenForm doc.Name, acDesign
With Forms(doc.Name)
If .HasModule Then
Debug.Print .Name, .Module.CountOfLines
End If
End With
DoCmd.Close acForm, doc.Name, acSaveNo
Next doc
' Count lines of code in Reports
For Each doc In dbother.Containers("Reports").Documents
DoCmd.OpenReport doc.Name, acDesign
With Reports(doc.Name)
If .HasModule Then
Debug.Print .Name, .Module.CountOfLines
End If
End With
DoCmd.Close acReport, doc.Name, acSaveNo
Next doc

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
Ron Carr
Guest
Posts: n/a
 
      14th Sep 2003
Thank you. I will give it a try.
"Marshall Barton" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Ron Carr wrote:
>
> >I have a databse which reviews other databases and counts objects.
> >I would also like to count the lines of code in Modules and forms in the
> >other databases, but cannot make the connection to do so.
> >I am aware of the properties that yiend the module line count, it is a
> >matter of connecting to the module / Form.

>
> You have to open an object before you can use its
> properties:
>
> ' Count lines of code in Modules
> For Each doc In dbother.Containers("Modules").Documents
> DoCmd.OpenModule doc.Name
> With Modules(doc.Name)
> Debug.Print .Name, .CountOfLines
> End With
> DoCmd.Close acModule, doc.Name, acSaveNo
> Next doc
> ' Count lines of code in Forms
> For Each doc In dbother.Containers("Forms").Documents
> DoCmd.OpenForm doc.Name, acDesign
> With Forms(doc.Name)
> If .HasModule Then
> Debug.Print .Name, .Module.CountOfLines
> End If
> End With
> DoCmd.Close acForm, doc.Name, acSaveNo
> Next doc
> ' Count lines of code in Reports
> For Each doc In dbother.Containers("Reports").Documents
> DoCmd.OpenReport doc.Name, acDesign
> With Reports(doc.Name)
> If .HasModule Then
> Debug.Print .Name, .Module.CountOfLines
> End If
> End With
> DoCmd.Close acReport, doc.Name, acSaveNo
> Next doc
>
> --
> Marsh
> MVP [MS Access]



 
Reply With Quote
 
Ron Carr
Guest
Posts: n/a
 
      14th Sep 2003
I tried the following code, and got message "Can't find the module basAudit"
which is in fact the first module in the target database. Any idea what is
wrong?

Public Sub CountModuleLines2()
Dim doc As Document

Set dbs = DBEngine.Workspaces(0).OpenDatabase("D:\Access\Eastman\Eastman
Conversion.mdb", _
dbname = "Eastman Conversion.mdb", , True)

For Each doc In dbs.Containers("Modules").Documents
DoCmd.OpenModule doc.Name (Error occurs here)
With Modules(doc.Name)
vmodulelinecount = vmodulelinecount + .CountOfLines
End With
DoCmd.Close acModule, doc.Name, acSaveNo
Next doc
MsgBox "vmodulelinecount = " & vmodulelinecount
End Sub

"Marshall Barton" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Ron Carr wrote:
>
> >I have a databse which reviews other databases and counts objects.
> >I would also like to count the lines of code in Modules and forms in the
> >other databases, but cannot make the connection to do so.
> >I am aware of the properties that yiend the module line count, it is a
> >matter of connecting to the module / Form.

>
> You have to open an object before you can use its
> properties:
>
> ' Count lines of code in Modules
> For Each doc In dbother.Containers("Modules").Documents
> DoCmd.OpenModule doc.Name
> With Modules(doc.Name)
> Debug.Print .Name, .CountOfLines
> End With
> DoCmd.Close acModule, doc.Name, acSaveNo
> Next doc
> ' Count lines of code in Forms
> For Each doc In dbother.Containers("Forms").Documents
> DoCmd.OpenForm doc.Name, acDesign
> With Forms(doc.Name)
> If .HasModule Then
> Debug.Print .Name, .Module.CountOfLines
> End If
> End With
> DoCmd.Close acForm, doc.Name, acSaveNo
> Next doc
> ' Count lines of code in Reports
> For Each doc In dbother.Containers("Reports").Documents
> DoCmd.OpenReport doc.Name, acDesign
> With Reports(doc.Name)
> If .HasModule Then
> Debug.Print .Name, .Module.CountOfLines
> End If
> End With
> DoCmd.Close acReport, doc.Name, acSaveNo
> Next doc
>
> --
> Marsh
> MVP [MS Access]



 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      14th Sep 2003
The DoCmd is working in your current database, so it refers to the Modules
collection in that database, not in your Eastman Conversion.mdb. You're
going to have to use Automation to be able to read the modules in another
database. Try something like:

Sub ReadModule()
Dim objAccess As Access.Application
Dim docCurr As Document
Dim lngModuleLineCount As Long

Set objAccess = New Access.Application
objAccess.OpenCurrentDatabase "D:\Access\Eastman\Eastman Conversion.mdb"

For Each docCurr In
objAccess.DBEngine.Workspaces(0).Databases(0).Containers("Modules").Document
s
objAccess.DoCmd.OpenModule docCurr.Name
With objAccess.Modules(docCurr.Name)
lngModuleLineCount = lngModuleLineCount + .CountOfLines
End With
objAccess.DoCmd.Close acModule, docCurr.Name, acSaveNo
Next docCurr
MsgBox "lngModuleLineCount = " & lngModuleLineCount

objAccess.CloseCurrentDatabase
Set objAccess = Nothing

End Sub

To learn more about using Automation with Access, check out:

ACC: Using Microsoft Access as an Automation Server
http://support.microsoft.com/?id=147816
ACC2000: Using Microsoft Access as an Automation Server
http://support.microsoft.com/?id=210111



--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele


"Ron Carr" <(E-Mail Removed)> wrote in message
news:jC09b.619$(E-Mail Removed)...
> I tried the following code, and got message "Can't find the module

basAudit"
> which is in fact the first module in the target database. Any idea what is
> wrong?
>
> Public Sub CountModuleLines2()
> Dim doc As Document
>
> Set dbs = DBEngine.Workspaces(0).OpenDatabase("D:\Access\Eastman\Eastman
> Conversion.mdb", _
> dbname = "Eastman Conversion.mdb", , True)
>
> For Each doc In dbs.Containers("Modules").Documents
> DoCmd.OpenModule doc.Name (Error occurs here)
> With Modules(doc.Name)
> vmodulelinecount = vmodulelinecount + .CountOfLines
> End With
> DoCmd.Close acModule, doc.Name, acSaveNo
> Next doc
> MsgBox "vmodulelinecount = " & vmodulelinecount
> End Sub
>
> "Marshall Barton" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Ron Carr wrote:
> >
> > >I have a databse which reviews other databases and counts objects.
> > >I would also like to count the lines of code in Modules and forms in

the
> > >other databases, but cannot make the connection to do so.
> > >I am aware of the properties that yiend the module line count, it is a
> > >matter of connecting to the module / Form.

> >
> > You have to open an object before you can use its
> > properties:
> >
> > ' Count lines of code in Modules
> > For Each doc In dbother.Containers("Modules").Documents
> > DoCmd.OpenModule doc.Name
> > With Modules(doc.Name)
> > Debug.Print .Name, .CountOfLines
> > End With
> > DoCmd.Close acModule, doc.Name, acSaveNo
> > Next doc
> > ' Count lines of code in Forms
> > For Each doc In dbother.Containers("Forms").Documents
> > DoCmd.OpenForm doc.Name, acDesign
> > With Forms(doc.Name)
> > If .HasModule Then
> > Debug.Print .Name, .Module.CountOfLines
> > End If
> > End With
> > DoCmd.Close acForm, doc.Name, acSaveNo
> > Next doc
> > ' Count lines of code in Reports
> > For Each doc In dbother.Containers("Reports").Documents
> > DoCmd.OpenReport doc.Name, acDesign
> > With Reports(doc.Name)
> > If .HasModule Then
> > Debug.Print .Name, .Module.CountOfLines
> > End If
> > End With
> > DoCmd.Close acReport, doc.Name, acSaveNo
> > Next doc
> >
> > --
> > Marsh
> > MVP [MS Access]

>
>



 
Reply With Quote
 
Ron Carr
Guest
Posts: n/a
 
      14th Sep 2003
That did it! Thanks. And thanks for thr references - I'll raed up some more.
"Douglas J. Steele" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The DoCmd is working in your current database, so it refers to the Modules
> collection in that database, not in your Eastman Conversion.mdb. You're
> going to have to use Automation to be able to read the modules in another
> database. Try something like:
>
> Sub ReadModule()
> Dim objAccess As Access.Application
> Dim docCurr As Document
> Dim lngModuleLineCount As Long
>
> Set objAccess = New Access.Application
> objAccess.OpenCurrentDatabase "D:\Access\Eastman\Eastman

Conversion.mdb"
>
> For Each docCurr In
>

objAccess.DBEngine.Workspaces(0).Databases(0).Containers("Modules").Document
> s
> objAccess.DoCmd.OpenModule docCurr.Name
> With objAccess.Modules(docCurr.Name)
> lngModuleLineCount = lngModuleLineCount + .CountOfLines
> End With
> objAccess.DoCmd.Close acModule, docCurr.Name, acSaveNo
> Next docCurr
> MsgBox "lngModuleLineCount = " & lngModuleLineCount
>
> objAccess.CloseCurrentDatabase
> Set objAccess = Nothing
>
> End Sub
>
> To learn more about using Automation with Access, check out:
>
> ACC: Using Microsoft Access as an Automation Server
> http://support.microsoft.com/?id=147816
> ACC2000: Using Microsoft Access as an Automation Server
> http://support.microsoft.com/?id=210111

\


 
Reply With Quote
 
Marshall Barton
Guest
Posts: n/a
 
      14th Sep 2003
Douglas J. Steele wrote:

>The DoCmd is working in your current database, so it refers to the Modules
>collection in that database, not in your Eastman Conversion.mdb. You're
>going to have to use Automation to be able to read the modules in another
>database. Try something like:
>
>Sub ReadModule()
>Dim objAccess As Access.Application
>Dim docCurr As Document
>Dim lngModuleLineCount As Long
>
> Set objAccess = New Access.Application
> objAccess.OpenCurrentDatabase "D:\Access\Eastman\Eastman Conversion.mdb"
>
> For Each docCurr In
>objAccess.DBEngine.Workspaces(0).Databases(0).Containers("Modules").Document
>s
> objAccess.DoCmd.OpenModule docCurr.Name
> With objAccess.Modules(docCurr.Name)
> lngModuleLineCount = lngModuleLineCount + .CountOfLines
> End With
> objAccess.DoCmd.Close acModule, docCurr.Name, acSaveNo
> Next docCurr
> MsgBox "lngModuleLineCount = " & lngModuleLineCount
>
> objAccess.CloseCurrentDatabase
> Set objAccess = Nothing
>
>End Sub
>
>To learn more about using Automation with Access, check out:
>
>ACC: Using Microsoft Access as an Automation Server
>http://support.microsoft.com/?id=147816
>ACC2000: Using Microsoft Access as an Automation Server
>http://support.microsoft.com/?id=210111


Aw sheesh, that'll teach me to take shortcuts when I check a
code snippet.

Thanks for bailing me out here Doug.

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      15th Sep 2003
"Marshall Barton" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Douglas J. Steele wrote:
>
> Aw sheesh, that'll teach me to take shortcuts when I check a
> code snippet.
>
> Thanks for bailing me out here Doug.


Hey, your code was interesting enough that I wanted to check out why it
wasn't working. <g>

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
undocumented alternative to module CountOfLines, Lines dgm Microsoft Access 3 25th Feb 2010 09:50 PM
Is there a way to read lines of a module NoSpam@aol.com Microsoft Excel Programming 3 5th Sep 2007 03:16 AM
Lines Count Bruce Microsoft C# .NET 3 29th Sep 2005 06:08 AM
Change Line Count to not count blank lines =?Utf-8?B?Q2Fyb2w=?= Microsoft Word Document Management 4 27th Nov 2004 01:46 PM
Lines in a Module(Procedure) Juan Melero Microsoft Excel Programming 7 30th Dec 2003 02:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:18 AM.