A
Andre L via AccessMonster.com
I thought this would be easy but have come up empty. We are cleaning up our
warehouse. I have been given a list of data items to be eliminated from the
warehouse. I have been asked to check our Access reports, and queries to see
if any of these fields are referenced. I wrote some code to look through
each query and return affect tables: I input a field on a form and click GO,
it returns a list of queries.
********************************************************************
Dim QueryNm As QueryDef
Dim TableNm As TableDef
Dim db As Database
Set db = CurrentDb()
With db
'Delete Table: tbl_TempList
For Each TableNm In .TableDefs
If TableNm.Name = "tbl_TempList" Then
DoCmd.DeleteObject acTable, "tbl_TempList"
End If
Next TableNm
'Create Table: tbl_TempList
Set TempTable = db.CreateTableDef("tbl_TempList")
With TempTable
.Fields.Append .CreateField("Name1", dbText)
End With
db.TableDefs.Append TempTable
'Start looking thru each Query's Sql to see if it contains the table name
desired,
'if so add it to the table: tbl_TempList
For Each QueryNm In .QueryDefs
If InStr(QueryNm.SQL, [Forms]![frmSearchQueriesForTableName]![TableName])
<> 0 Then
Indicator = "Found"
sqlstr = "INSERT INTO tbl_TempList(Name1) VALUES ('"
sqlstr = sqlstr & QueryNm.Name & "');"
DoCmd.RunSQL sqlstr
End If
Next QueryNm
End With
If Indicator = "Found" Then
MsgBox "Done!---Will Now Open the List for you."
DoCmd.OpenTable "tbl_TempList", acViewNormal
Else
MsgBox "Done!---No matches found."
End If
DoCmd.SetWarnings True
**************************************************************************
I wish to do somethong similar with Reports, ie look at every report and
every item printed and determine which reports print the fields they are
deleteing from the warehouse. I am stumped as to how to procede. There is
no ReportDefs variable.
Any ideas....
warehouse. I have been given a list of data items to be eliminated from the
warehouse. I have been asked to check our Access reports, and queries to see
if any of these fields are referenced. I wrote some code to look through
each query and return affect tables: I input a field on a form and click GO,
it returns a list of queries.
********************************************************************
Dim QueryNm As QueryDef
Dim TableNm As TableDef
Dim db As Database
Set db = CurrentDb()
With db
'Delete Table: tbl_TempList
For Each TableNm In .TableDefs
If TableNm.Name = "tbl_TempList" Then
DoCmd.DeleteObject acTable, "tbl_TempList"
End If
Next TableNm
'Create Table: tbl_TempList
Set TempTable = db.CreateTableDef("tbl_TempList")
With TempTable
.Fields.Append .CreateField("Name1", dbText)
End With
db.TableDefs.Append TempTable
'Start looking thru each Query's Sql to see if it contains the table name
desired,
'if so add it to the table: tbl_TempList
For Each QueryNm In .QueryDefs
If InStr(QueryNm.SQL, [Forms]![frmSearchQueriesForTableName]![TableName])
<> 0 Then
Indicator = "Found"
sqlstr = "INSERT INTO tbl_TempList(Name1) VALUES ('"
sqlstr = sqlstr & QueryNm.Name & "');"
DoCmd.RunSQL sqlstr
End If
Next QueryNm
End With
If Indicator = "Found" Then
MsgBox "Done!---Will Now Open the List for you."
DoCmd.OpenTable "tbl_TempList", acViewNormal
Else
MsgBox "Done!---No matches found."
End If
DoCmd.SetWarnings True
**************************************************************************
I wish to do somethong similar with Reports, ie look at every report and
every item printed and determine which reports print the fields they are
deleteing from the warehouse. I am stumped as to how to procede. There is
no ReportDefs variable.
Any ideas....