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

MS Access code documentation 3

Status
Not open for further replies.

njegus

IS-IT--Management
Feb 11, 2004
5
NL
Hi all,

I am a new MS Access programer although I have experience is other languages.

I have an MS Access application with lots of modules, forms and reports with lot of access basic code. The code is documented (funtion headers with parameters description and so).

Now, I need to write some technical manuals describing these functions. I know that there are tools to make this in Visual Basic (and in other languages like java -> javadoc).

Anybody knows a tool that integrates in MS Access to do this?
How do you make the documentation for MS Access aplications?

Thanks a lot in advance

David
 
The following functions return a list of details for various database object types (including details of functions and subs).

It should be fairly easy to modify the function listing procedure to return the comments relating to the function too......

Option Compare Database
Option Explicit

Public Function ListForms()

Dim ThisDB As DAO.Database
Dim varForm As DAO.Document
Dim strList As String

Set ThisDB = CurrentDb

For Each varForm In ThisDB.Containers("Forms").Documents
strList = strList & vbCrLf & varForm.Name
Next varForm

strList = Right$(strList, Len(strList) - 2)

ListForms = strList

End Function

Public Function ListTables()

Dim ThisDB As DAO.Database
Dim TDef As DAO.TableDef
Set ThisDB = CurrentDb
Dim strList As String

For Each TDef In ThisDB.TableDefs
strList = strList & vbCrLf & TDef.Name
Next TDef

strList = Right$(strList, Len(strList) - 2)

ListTables = strList

End Function

Public Function ListFields(ByVal strTabName As String) As String

Dim ThisDB As DAO.Database
Dim TDef As DAO.TableDef
Dim MyField As DAO.Field
Dim strList As String

Set ThisDB = CurrentDb
Set TDef = ThisDB.TableDefs(strTabName)

For Each MyField In TDef.Fields
strList = strList & vbCrLf & MyField.Name
Next MyField


ListFields = strList

End Function

Public Function CountTDefs() As Integer

Dim ThisDB As DAO.Database
Dim TDef As DAO.TableDef
Dim intCount As Integer

Set ThisDB = CurrentDb

For Each TDef In ThisDB.TableDefs
intCount = intCount + 1
Next TDef

CountTDefs = intCount

End Function

Public Function FieldCount(ByVal strTabName As String) As Integer

Dim ThisDB As DAO.Database
Dim TDef As DAO.TableDef
Dim MyField As DAO.Field
Dim intCount As Integer

Set ThisDB = CurrentDb
Set TDef = ThisDB.TableDefs(strTabName)

For Each MyField In TDef.Fields
intCount = intCount + 1
Next MyField

FieldCount = intCount

End Function

Public Function ListFieldTypes(ByVal strTabName As String) As String

Dim ThisDB As DAO.Database
Dim TDef As DAO.TableDef
Dim MyField As DAO.Field
Dim strList As String

Set ThisDB = CurrentDb
Set TDef = ThisDB.TableDefs(strTabName)

For Each MyField In TDef.Fields
strList = strList & vbCrLf & DataTypeNumToText(MyField.Type)
Next MyField

ListFieldTypes = strList

End Function

Private Function DataTypeNumToText(ByVal intTypeNum As Integer) As String

Select Case intTypeNum
Case 1
DataTypeNumToText = "Boolean"
Case 2
DataTypeNumToText = "Byte"
Case 3
DataTypeNumToText = "Integer"
Case 4
DataTypeNumToText = "Long Integer"
Case 5
DataTypeNumToText = "Currency"
Case 7
DataTypeNumToText = "Double Precision"
Case 8
DataTypeNumToText = "Date"
Case 9
DataTypeNumToText = "Binary"
Case 10
DataTypeNumToText = "Text"
Case 12
DataTypeNumToText = "Memo"
Case 16
DataTypeNumToText = "Auto Number"
Case 19
DataTypeNumToText = "Numeric" '???why when each numeric data type has it's own number???
Case 20
DataTypeNumToText = "Decimal"
End Select

End Function

Public Function ListFieldLengths(ByVal strTabName As String) As String

Dim ThisDB As DAO.Database
Dim TDef As DAO.TableDef
Dim MyField As DAO.Field
Dim strList As String

Set ThisDB = CurrentDb
Set TDef = ThisDB.TableDefs(strTabName)

For Each MyField In TDef.Fields
strList = strList & vbCrLf & MyField.Size
Next MyField

ListFieldLengths = strList

End Function

Public Function ListValRules(ByVal strTabName As String)

Dim ThisDB As DAO.Database
Dim TDef As DAO.TableDef
Dim MyField As DAO.Field
Dim strList As String

Set ThisDB = CurrentDb
Set TDef = ThisDB.TableDefs(strTabName)

For Each MyField In TDef.Fields
strList = strList & vbCrLf & MyField.ValidationRule
Next MyField

ListValRules = strList

End Function

Public Function SQL_Search(strKeyWord) As String

Dim ThisDB As DAO.Database
Dim QDef As DAO.QueryDef
Dim strList As String

Set ThisDB = CurrentDb

For Each QDef In ThisDB.QueryDefs
If QDef.SQL Like "*" & strKeyWord & "*" Then
strList = strList & vbCrLf & QDef.Name
End If
Next QDef

SQL_Search = strList

End Function

Public Function CountMacros() As Integer

Dim ThisDB As DAO.Database
Dim docMac As Document
Dim Count As Integer

Set ThisDB = CurrentDb

For Each docMac In ThisDB.Containers("Scripts").Documents
Count = Count + 1
Next docMac

CountMacros = Count

End Function

Public Function CountQDefs()

Dim ThisDB As DAO.Database
Dim QDef As DAO.QueryDef
Dim Count As Integer

Set ThisDB = CurrentDb

For Each QDef In ThisDB.QueryDefs
Count = Count + 1
Next QDef

CountQDefs = Count

End Function

Public Function CountMods()

Dim ThisDB As DAO.Database
Dim docMod As DAO.Document
Dim Count As Integer

Set ThisDB = CurrentDb

For Each docMod In ThisDB.Containers("Modules").Documents
Count = Count + 1
Next docMod

CountMods = Count

End Function

Public Function ListFunctions() As Integer

Dim ThisDB As DAO.Database
Dim docMod As DAO.Document
Dim ModVB As Access.Module
Dim lngLineIndex As Long: lngLineIndex = 1
Dim strLine As String
Dim strList As String

Set ThisDB = CurrentDb

For Each docMod In ThisDB.Containers("Modules").Documents
Set ModVB = Application.Modules(docMod.Name)
Do While lngLineIndex <= ModVB.CountOfLines
strLine = ModVB.Lines(lngLineIndex, 1)
If strLine Like "Private Sub*" Or strLine Like "Public Sub*" Or strLine Like "Private Function*" Or strLine Like "Public Function*" Then
strList = strList & vbCrLf & strLine
End If
lngLineIndex = lngLineIndex + 1
Loop
Next docMod


ListFunctions = strList

End Function

Public Function ListMods() As String

Dim ThisDB As DAO.Database
Dim docMod As DAO.Document
Dim strList As String

Set ThisDB = CurrentDb

For Each docMod In ThisDB.Containers("Modules").Documents
strList = strList & vbCrLf & docMod.Name
Next docMod

ListMods = strList


End Function

Public Function ContainsField(ByVal strFieldName As String, Optional ByVal blnUseWildCards As Boolean = True) As String

Dim ThisDB As DAO.Database
Dim TDef As DAO.TableDef
Dim MyField As DAO.Field
Dim strList As String

Set ThisDB = CurrentDb

For Each TDef In ThisDB.TableDefs
For Each MyField In TDef.Fields
If blnUseWildCards = True Then
If MyField.Name Like "*" & strFieldName & "*" Then
strList = strList & vbCrLf & TDef.Name
Exit For 'No need to carry on checking this table
End If
Else
If MyField.Name = strFieldName Then
strList = strList & vbCrLf & TDef.Name
Exit For 'No need to carry on checking this table
End If
End If
Next MyField
Next TDef

ContainsField = strList

End Function

Please do not feed the trolls.....
 
Thanks a lot Ed, but I was looking for a 'commercial' tool or something like that because I haven't got much time to investigate and fix your code to my requeriments.

What do you use to make documentation?
Your code returns the code details only for Modules or for Reports and Forms too?

Thanks again
 
I'm not aware of any commercial tools that do this for Access - I wrote my own documenting utility.

The code I have posted only lists functions and subs in modules, not behind forms or reports. I do have something that will do this though.

If you want a copy of my tool post your email address and I'll try and send it to you (it's a little on the large size though - I'm not sure it will be emailable).

Please do not feed the trolls.....
 
My email address is david.sauce@ingrealestate.com and if the size is not greater than 5Mb send it to david.sauce@ingrealestateiberica.es too please.

Maybe you can cut your tool in several files with winzip or hacha tools.

Thanks a lot.
 
Why not just use the documentor that comes with Access?

Tools | Analyze | Documentor

Then just select the Modules tab if code is all you want - it works good enough for me.

HTH
 
The system will need some of my security features removing before I send it to you.

I'll try and get it sorted today, otherwise I'll do it over the weekend.

Ed Metcalfe.

Please do not feed the trolls.....
 
You can use the following code to get a count of the number of lines in an Access app, and you can adapt it to return other properties as well.

Sub LinesInMods()
Dim lines As Long
Dim m As AccessObject

For Each m In CodeProject.AllModules
DoCmd.OpenModule m.Name
With Modules(m.Name)
lines = lines+.CountOfLines+.CountOfDeclarationLines
Debug.Print .Name & ": " & vbTab & .CountOfLines+.CountOfDeclarationLines
End With
Next m

Debug.Print "TOTAL LINES IN BAS/CLASS MODS: " & lines

End Sub

Sub LinesInForms()
Dim lines As Long
Dim f As AccessObject

For Each f In CurrentProject.AllForms
DoCmd.OpenForm f.Name, acDesign, , , , acHidden

With Forms(f.Name).Module
lines = lines+.CountOfLines+.CountOfDeclarationLines
Debug.Print .Name & ": " & vbTab & .CountOfLines+.CountOfDeclarationLines
End With

DoCmd.Close acForm, f.Name, acSaveNo
Next f

Debug.Print "TOTAL LINES IN FORM MODS: " & lines

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top