JohnE said:
Hello. The boss is beginning to ask about the number of lines of code that
there is in different Access databases that have been created and those
currently under construction. Does Access have a way of determining that or
is there another method for determining (other then actually counting)?
No simple way to do that.
Here's a procedure you can put in a module and call from the
immediate window:
Public Function LinesOfCode() As Long
Dim dbCur As Database
Dim doc As Document
Set dbCur = CurrentDb
' Count lines of code in Modules
For Each doc In dbCur.Containers("Modules").Documents
DoCmd.OpenModule doc.Name
LinesOfCode = LinesOfCode + _
LinesInModule(Modules(doc.Name))
DoCmd.Close acModule, doc.Name, acSaveNo
Next doc
' Count lines of code in Forms
For Each doc In dbCur.Containers("Forms").Documents
DoCmd.OpenForm doc.Name, acDesign
With Forms(doc.Name)
If .HasModule Then
LinesOfCode = LinesOfCode + _
LinesInModule(.Module)
End If
End With
DoCmd.Close acForm, doc.Name, acSaveNo
Next doc
' Count lines of code in Reports
For Each doc In dbCur.Containers("Reports").Documents
DoCmd.OpenReport doc.Name, acDesign
With Reports(doc.Name)
If .HasModule Then
LinesOfCode = LinesOfCode + _
LinesInModule(.Module)
End If
End With
DoCmd.Close acReport, doc.Name, acSaveNo
Next doc
Set dbCur = Nothing
End Function
Public Function LinesInModule(mdl As Module) As Long
Dim lngLineNo As Long
Dim strLine As String
For lngLineNo = 1 To mdl.CountOfLines
strLine = Trim$(mdl.Lines(lngLineNo, 1))
If strLine <> "" And Left$(strLine, 1) <> "'" Then
LinesInModule = LinesInModule + 1
End If
Next lngLineNo
End Function
Be sure to tell your boss that lines of code is a silly
measurement of anything ;-)