mikethewizz
New member
- Local time
- Today, 14:26
- Joined
- May 9, 2006
- Messages
- 3
All,
I am attempting to write a utility to analyze a specified Access database to determine what objects are used and what is unused. For example. Test every table, for use in any query SQL, form, or VBA code in modules, etc...
Once completed, it will produce a list of all objects that are not used somewhere in the dB.
This will allow me to clean up several old process dBs. With out having to manually review each part of the dB.
Well, enough back ground. Here is my problem.
I want to analyze the built in MS Access Macros to see what Queries, Tables, VBA Code.... is called by each macro.
If I can access the steps in the macro via code I could pass a simple text string and validate whether or not the object is used in any macro.
Here is a sample of my code for checking for a table in all queries.
In the function below I pass the object name, and object type for reporting.
The code will capture the queries, where and object is used, or will capture the object as not being used after testing all queries.
--BEGIN CODE--
Function TestForTblOrQryInSQL(strTblQrySearch As String, strObjType As String) As String
Dim qry1 As QueryDef
Dim blnTblFoundInAnyQry As Boolean
Dim blnTblFoundInCurrQry As Boolean
Dim intQryLoop As Integer
Dim rst2 As DAO.Recordset
blnTblFoundInAnyQry = False
For Each qry1 In CurrentDb.QueryDefs
blnTblFoundInCurrQry = False
If InStr(1, qry1.SQL, strTblQrySearch) <> 0 Then
intQryLoop = 1
Do Until intQryLoop > 6
Select Case intQryLoop
Case 1
If InStr(1, qry1.SQL, " " & strTblQrySearch & " ") <> 0 Then
'Record Table and Qry name
blnTblFoundInCurrQry = True
End If
Case 2
If InStr(1, qry1.SQL, " " & strTblQrySearch & Chr(13)) <> 0 Then
'Record Table and Qry name
blnTblFoundInCurrQry = True
End If
Case 3
If InStr(1, qry1.SQL, " " & strTblQrySearch & ";") <> 0 Then
'Record Table and Qry name
blnTblFoundInCurrQry = True
End If
Case 4
If InStr(1, qry1.SQL, " [" & strTblQrySearch & "] ") <> 0 Then
'Record Table and Qry name
blnTblFoundInCurrQry = True
End If
Case 5
If InStr(1, qry1.SQL, " [" & strTblQrySearch & "]" & Chr(13)) <> 0 Then
'Record Table and Qry name
blnTblFoundInCurrQry = True
End If
Case 6
If InStr(1, qry1.SQL, " [" & strTblQrySearch & "];") <> 0 Then
'Record Table and Qry name
blnTblFoundInCurrQry = True
End If
End Select
If blnTblFoundInCurrQry = True Then
intQryLoop = 7
Else
intQryLoop = intQryLoop + 1
End If
Loop
If blnTblFoundInCurrQry = True Then
'Record Table and Qry Name
Set rst2 = CurrentDb.OpenRecordset("db_Clean_Objs_Uses")
rst2.AddNew
rst2!ObjName = strTblQrySearch
rst2!ObjType = strObjType
rst2!ObjTypeUsed = "Qry"
rst2!ObjNameUsed = qry1.Name
rst2.Update
Set rst2 = Nothing
blnTblFoundInAnyQry = True
End If
End If
Next qry1
If blnTblFoundInAnyQry = False Then
Set rst2 = CurrentDb.OpenRecordset("db_Clean_Objs_No_Uses")
rst2.AddNew
rst2!ObjName = strTblQrySearch
rst2!ObjType = strObjType
rst2.Update
Set rst2 = Nothing
End If
End Function
--END CODE--
I am using MS Access 2002 (XP)
I hope this make sense.
Thanks in advance for any input.
I am attempting to write a utility to analyze a specified Access database to determine what objects are used and what is unused. For example. Test every table, for use in any query SQL, form, or VBA code in modules, etc...
Once completed, it will produce a list of all objects that are not used somewhere in the dB.
This will allow me to clean up several old process dBs. With out having to manually review each part of the dB.
Well, enough back ground. Here is my problem.
I want to analyze the built in MS Access Macros to see what Queries, Tables, VBA Code.... is called by each macro.
If I can access the steps in the macro via code I could pass a simple text string and validate whether or not the object is used in any macro.
Here is a sample of my code for checking for a table in all queries.
In the function below I pass the object name, and object type for reporting.
The code will capture the queries, where and object is used, or will capture the object as not being used after testing all queries.
--BEGIN CODE--
Function TestForTblOrQryInSQL(strTblQrySearch As String, strObjType As String) As String
Dim qry1 As QueryDef
Dim blnTblFoundInAnyQry As Boolean
Dim blnTblFoundInCurrQry As Boolean
Dim intQryLoop As Integer
Dim rst2 As DAO.Recordset
blnTblFoundInAnyQry = False
For Each qry1 In CurrentDb.QueryDefs
blnTblFoundInCurrQry = False
If InStr(1, qry1.SQL, strTblQrySearch) <> 0 Then
intQryLoop = 1
Do Until intQryLoop > 6
Select Case intQryLoop
Case 1
If InStr(1, qry1.SQL, " " & strTblQrySearch & " ") <> 0 Then
'Record Table and Qry name
blnTblFoundInCurrQry = True
End If
Case 2
If InStr(1, qry1.SQL, " " & strTblQrySearch & Chr(13)) <> 0 Then
'Record Table and Qry name
blnTblFoundInCurrQry = True
End If
Case 3
If InStr(1, qry1.SQL, " " & strTblQrySearch & ";") <> 0 Then
'Record Table and Qry name
blnTblFoundInCurrQry = True
End If
Case 4
If InStr(1, qry1.SQL, " [" & strTblQrySearch & "] ") <> 0 Then
'Record Table and Qry name
blnTblFoundInCurrQry = True
End If
Case 5
If InStr(1, qry1.SQL, " [" & strTblQrySearch & "]" & Chr(13)) <> 0 Then
'Record Table and Qry name
blnTblFoundInCurrQry = True
End If
Case 6
If InStr(1, qry1.SQL, " [" & strTblQrySearch & "];") <> 0 Then
'Record Table and Qry name
blnTblFoundInCurrQry = True
End If
End Select
If blnTblFoundInCurrQry = True Then
intQryLoop = 7
Else
intQryLoop = intQryLoop + 1
End If
Loop
If blnTblFoundInCurrQry = True Then
'Record Table and Qry Name
Set rst2 = CurrentDb.OpenRecordset("db_Clean_Objs_Uses")
rst2.AddNew
rst2!ObjName = strTblQrySearch
rst2!ObjType = strObjType
rst2!ObjTypeUsed = "Qry"
rst2!ObjNameUsed = qry1.Name
rst2.Update
Set rst2 = Nothing
blnTblFoundInAnyQry = True
End If
End If
Next qry1
If blnTblFoundInAnyQry = False Then
Set rst2 = CurrentDb.OpenRecordset("db_Clean_Objs_No_Uses")
rst2.AddNew
rst2!ObjName = strTblQrySearch
rst2!ObjType = strObjType
rst2.Update
Set rst2 = Nothing
End If
End Function
--END CODE--
I am using MS Access 2002 (XP)
I hope this make sense.
Thanks in advance for any input.