I'm trying to make sense of some old databases. Each has a large number of tables and forms I'm sure aren't needed any more and I want to get rid of them.
The Object Dependencies tool is useful but, given the hundreds of items I'm checking, slower than I'd like.
I found some code to search for all queries that use a certain table, this works very well.
What I can't find or figure out is a way to use VBA to check if a table is used by a form. This could be either as the form's data source or to populate a combo box/list box on the form.
Is anyone aware of anything like this? I'm assuming it's possible and just beyond my abilities.
In case it helps, following is the code that checks queries for a given table.
The Object Dependencies tool is useful but, given the hundreds of items I'm checking, slower than I'd like.
I found some code to search for all queries that use a certain table, this works very well.
What I can't find or figure out is a way to use VBA to check if a table is used by a form. This could be either as the form's data source or to populate a combo box/list box on the form.
Is anyone aware of anything like this? I'm assuming it's possible and just beyond my abilities.
In case it helps, following is the code that checks queries for a given table.
Code:
Function Check_Queries(strName As String, Db As Database)
Dim strSQL As String
Dim Rst As Recordset
strSQL = "SELECT DISTINCT " & _
"MSysObjects.Name AS QueryName " & _
"From MSysQueries INNER Join MSysObjects " & _
"ON MSysQueries.ObjectId = MSysObjects.Id " & _
"WHERE " & _
"(MSysQueries.Name1 Like '*" & strName & "*' " & _
"OR MSysQueries.Name2 Like '*" & strName & "*' " & _
"OR MSysQueries.Expression Like '*" & strName & "*') " & _
"AND MSysObjects.Name Not Like '*sq_CF*' " & _
"AND MSysObjects.Name Not Like '*MSys*'" & _
"AND MSysObjects.Name Not Like '*~*'"
Set Rst = Db.OpenRecordset(strSQL)
If Not Rst.EOF Then
Rst.MoveFirst
Do While Not Rst.EOF
With txtResults
.SetFocus
.Value = txtResults & "[" & strName & "] is used by [" & Rst!QueryName & "] <BR>"
.SelStart = Len(.Value)
End With
Rst.MoveNext
Loop
Else
With txtResults
.SetFocus
.Value = txtResults & "No queries reference table [" & strName & "] <BR>"
.SelStart = Len(.Value)
End With
End If
End Function