PSLine2000Documentation/Modules/SummaryModule.md

263 lines
9.9 KiB
Markdown

# SummaryModule
Analysis generated on: 4/1/2025 5:16:54 PM
---
## VBA Code
```vba
Attribute VB_Name = "SummaryModule"
Option Compare Database
Option Explicit
' Subroutine to generate a summary of the entire database
Public Sub GenerateDatabaseSummary()
Dim fso As Object
Dim overviewFile As Object
Dim summaryFile As Object
Dim vaultPath As String
Dim overviewPath As String
Dim summaryPath As String
On Error GoTo ErrorHandler
' Set up the FileSystemObject
Debug.Print "Creating FileSystemObject"
Set fso = CreateObject("Scripting.FileSystemObject")
If fso Is Nothing Then
Debug.Print "Failed to create FileSystemObject"
MsgBox "Failed to create FileSystemObject. Error: " & Err.Description, vbCritical
Exit Sub
End If
Debug.Print "FileSystemObject created successfully"
' Define paths
vaultPath = CurrentProject.Path & "\ObsidianVault"
overviewPath = vaultPath & "\Overview.md"
summaryPath = vaultPath & "\WhatItDoes.md"
' Check if the vault folder exists
Debug.Print "Checking vault folder: " & vaultPath
If Not fso.FolderExists(vaultPath) Then
Debug.Print "Vault folder does not exist: " & vaultPath
MsgBox "Vault folder does not exist: " & vaultPath & ". Please run the other documentation modules first.", vbCritical
Exit Sub
End If
' Create the summary file
Debug.Print "Creating summary file: " & summaryPath
Set summaryFile = fso.CreateTextFile(summaryPath, True)
If summaryFile Is Nothing Then
Debug.Print "Failed to create WhatItDoes.md"
MsgBox "Failed to create WhatItDoes.md. Error: " & Err.Description, vbCritical
Exit Sub
End If
Debug.Print "Summary file created successfully"
' Write the summary header
summaryFile.WriteLine "# What It Does: Database Summary"
summaryFile.WriteLine "Generated on: " & Now
summaryFile.WriteLine "---"
summaryFile.WriteLine "## Overview"
summaryFile.WriteLine "This document provides a high-level summary of the Access database, aggregating information from the documentation of its Queries, Forms, Tables, Modules, and Macros."
summaryFile.WriteLine ""
' Initialize counters
Dim queryCount As Long
Dim formCount As Long
Dim tableCount As Long
Dim moduleCount As Long
Dim macroCount As Long
queryCount = 0
formCount = 0
tableCount = 0
moduleCount = 0
macroCount = 0
' Lists to store component names
Dim queriesList As String
Dim formsList As String
Dim tablesList As String
Dim modulesList As String
Dim macrosList As String
queriesList = ""
formsList = ""
tablesList = ""
modulesList = ""
macrosList = ""
' Check if Overview.md exists
If fso.FileExists(overviewPath) Then
Debug.Print "Reading Overview.md: " & overviewPath
Set overviewFile = fso.OpenTextFile(overviewPath, 1) ' 1 = ForReading
Dim overviewText As String
overviewText = overviewFile.ReadAll
overviewFile.Close
Set overviewFile = Nothing
' Split the overview text into lines
Dim lines() As String
lines = Split(overviewText, vbCrLf)
Dim i As Long
Dim currentSection As String
currentSection = ""
For i = LBound(lines) To UBound(lines)
Dim line As String
line = Trim(lines(i))
' Identify the current section
If InStr(1, line, "## Queries", vbTextCompare) > 0 Then
currentSection = "Queries"
ElseIf InStr(1, line, "## Forms", vbTextCompare) > 0 Then
currentSection = "Forms"
ElseIf InStr(1, line, "## Tables", vbTextCompare) > 0 Then
currentSection = "Tables"
ElseIf InStr(1, line, "## Modules", vbTextCompare) > 0 Then
currentSection = "Modules"
ElseIf InStr(1, line, "## Macros", vbTextCompare) > 0 Then
currentSection = "Macros"
ElseIf InStr(1, line, "## Analysis Complete", vbTextCompare) > 0 Then
currentSection = ""
End If
' Process the line based on the current section
If currentSection <> "" And Left(line, 2) = "- " And Not InStr(1, line, "Error:", vbTextCompare) > 0 Then
' Extract the component name from the link
Dim componentName As String
Dim startPos As Long
Dim endPos As Long
startPos = InStr(1, line, "[[") + 2
endPos = InStr(startPos, line, "]]")
If startPos > 2 And endPos > startPos Then
componentName = Mid(line, startPos, endPos - startPos)
' Remove the section prefix (e.g., "Queries/")
Dim slashPos As Long
slashPos = InStr(1, componentName, "/")
If slashPos > 0 Then
componentName = Mid(componentName, slashPos + 1)
End If
' Add to the appropriate list and increment the counter
Select Case currentSection
Case "Queries"
queryCount = queryCount + 1
queriesList = queriesList & "- [[" & currentSection & "/" & componentName & "]]" & vbCrLf
Case "Forms"
formCount = formCount + 1
formsList = formsList & "- [[" & currentSection & "/" & componentName & "]]" & vbCrLf
Case "Tables"
tableCount = tableCount + 1
tablesList = tablesList & "- [[" & currentSection & "/" & componentName & "]]" & vbCrLf
Case "Modules"
moduleCount = moduleCount + 1
modulesList = modulesList & "- [[" & currentSection & "/" & componentName & "]]" & vbCrLf
Case "Macros"
macroCount = macroCount + 1
macrosList = macrosList & "- [[" & currentSection & "/" & componentName & "]]" & vbCrLf
End Select
End If
ElseIf currentSection <> "" And InStr(1, line, "*No ", vbTextCompare) > 0 Then
' Handle the case where no components are found
Select Case currentSection
Case "Queries"
queryCount = 0
queriesList = "- *No queries found*" & vbCrLf
Case "Forms"
formCount = 0
formsList = "- *No forms found*" & vbCrLf
Case "Tables"
tableCount = 0
tablesList = "- *No tables found*" & vbCrLf
Case "Modules"
moduleCount = 0
modulesList = "- *No modules found*" & vbCrLf
Case "Macros"
macroCount = 0
macrosList = "- *No macros found*" & vbCrLf
End Select
End If
Next i
Else
Debug.Print "Overview.md not found: " & overviewPath
summaryFile.WriteLine "## Error"
summaryFile.WriteLine "- *Overview.md not found. Please run the other documentation modules first.*"
summaryFile.Close
Set summaryFile = Nothing
Set fso = Nothing
MsgBox "Overview.md not found: " & overviewPath & ". Please run the other documentation modules first.", vbCritical
Exit Sub
End If
' Write the summary counts
summaryFile.WriteLine "## Summary Counts"
summaryFile.WriteLine "- **Total Queries**: " & queryCount
summaryFile.WriteLine "- **Total Forms**: " & formCount
summaryFile.WriteLine "- **Total Tables**: " & tableCount
summaryFile.WriteLine "- **Total Modules**: " & moduleCount
summaryFile.WriteLine "- **Total Macros**: " & macroCount
summaryFile.WriteLine ""
' Write the detailed lists
summaryFile.WriteLine "## Queries (" & queryCount & ")"
If queryCount > 0 Then
summaryFile.Write queriesList
Else
summaryFile.WriteLine queriesList
End If
summaryFile.WriteLine ""
summaryFile.WriteLine "## Forms (" & formCount & ")"
If formCount > 0 Then
summaryFile.Write formsList
Else
summaryFile.WriteLine formsList
End If
summaryFile.WriteLine ""
summaryFile.WriteLine "## Tables (" & tableCount & ")"
If tableCount > 0 Then
summaryFile.Write tablesList
Else
summaryFile.WriteLine tablesList
End If
summaryFile.WriteLine ""
summaryFile.WriteLine "## Modules (" & moduleCount & ")"
If moduleCount > 0 Then
summaryFile.Write modulesList
Else
summaryFile.WriteLine modulesList
End If
summaryFile.WriteLine ""
summaryFile.WriteLine "## Macros (" & macroCount & ")"
If macroCount > 0 Then
summaryFile.Write macrosList
Else
summaryFile.WriteLine macrosList
End If
summaryFile.WriteLine ""
' Finalize and clean up
Debug.Print "Closing summary file"
summaryFile.Close
Set summaryFile = Nothing
Set fso = Nothing
MsgBox "Database summary complete. File saved to: " & summaryPath, vbInformation
Exit Sub
ErrorHandler:
Debug.Print "Error in GenerateDatabaseSummary: " & Err.Number & ": " & Err.Description & " at " & Now
If Not summaryFile Is Nothing Then
Debug.Print "Closing summaryFile in error handler"
summaryFile.Close
Set summaryFile = Nothing
End If
Set fso = Nothing
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical
Exit Sub
End Sub
```
## What it does
*No VBA code to document due to export failure*