If Mohammed won't go to the System Tables...
The Source Code
Option Compare Database ' Use database order for string comparisons
Sub CreateDependencies (sSource As String, sDest As String)
Dim sSQL As String
Dim qrySupport As QueryDef
Dim qryCreate As QueryDef
Dim dbCurr As Database ' Put current db into a convenient object
Set dbCurr = DBEngine.Workspaces(0).Databases(0)
' Generate SQL string - support Querydef
sSQL = "SELECT DISTINCTROW " & sSource & ".Name AS [Object Name], MSysObjects.Name AS Dependency "
sSQL = sSQL & "FROM " & sSource & ", MSysObjects "
sSQL = sSQL & "WHERE (((InStr([" & sSource & "].[SQL],[MSysObjects].[Name]))<>0)) "
sSQL = sSQL & "ORDER BY"& sSource & ".Name;" ' Create Querydef of Support Query
Set qrySupport = dbCurr.CreateQueryDef ("GetDependencies", sSQL)
qrySupport.Close ' Execute SQL string to turn query results into table
dbCurr.Execute "SELECT * INTO " & sDest & " FROM GetDependencies;"
' Remove Support query from database
dbCurr.Querydefs.Delete "GetDependencies"
End Sub
Function CreateResultTable (dbTarget As Database, sBaseName As String) As String
Dim iNum As Integer
Dim iTries As Integer
Dim sTableName As String
Dim iSuccess As Integer
Dim iExists As Integer ' Create tabledef to add to dbTarget database called the passed base name or base name with number appropriate
iSuccess = False
iTries = 0
Do ' Build name to test for
sTableName = sBaseName & Format$ (iTries, "#")
iExists = False
iNum = 0 ' Check name existing in tabledefs
Do
If dbTarget.tabledefs(iNum).Name = sTableName Then
' Can't use this name
iExists = True
End If
iNum = iNum + 1
Loop Until (iNum = dbTarget.tabledefs.Count) Or (iExists <> False)
' Found a name that didn't exist
If iExists = False Then ' Create the table
Dim tdTemp As New TableDef
tdTemp.Name = sTableName ' Add field to store querydef names
Dim fldName As New Field
fldName.Name = "Name"
fldName.Type = DB_Text
fldName.Size = 64
tdTemp.Fields.Append fldName ' Add field to store the SQL string
Dim fldSQL As New Field
fldSQL.Name = "SQL"
fldSQL.Type = DB_MEMO
fldSQL.Size = 62000
tdTemp.Fields.Append fldSQL ' Append table to database
dbTarget.tabledefs.Append tdTemp
iSuccess = True
End If
iTries = iTries + 1
Loop Until iSuccess <> False ' Pass back name of created table
CreateResultTable = sTableName
End Function
Sub GetSQLStrings () ' Declare required variables
Dim dbCurr As Database
Dim dsResult As Dynaset
Dim iNum As Integer ' Put current db into a convenient object
Set dbCurr = DBEngine.Workspaces(0).Databases(0)
' Create table to hold results & open a dynaset on it
Set dsResult = dbCurr.CreateDynaset (CreateResultTable(dbCurr, "tblResult"))
' Iterate through Querydefs collection
iNum = 0
Do ' Add querydef and SQL string (direct from QueryDef object) to the results table
dsResult.AddNew
dsResult!Name = dbCurr.Querydefs(iNum).Name
dsResult!SQL = dbCurr.Querydefs(iNum).SQL
dsResult.Update
iNum = iNum + 1 ' Give db engine time to catch breath
DBEngine.Idle
Loop Until iNum = dbCurr.Querydefs.Count
End Sub
![]()