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]
>
>