R
robertfuschetto via AccessMonster.com
This code is suppose to open a table containing about 30 table names. It
should them look through the sql of each query in the db and see if the table
name is referenced. If so, it sets an indicator to true and writes that
query name to a separate table. It then searches for the remainder of the 30
or so tables. Here is the code. As of now I get a Compile error on the
line: For Each QueryNm In .QueryDefs. It says method or data member not
found. To be honest I am uneasy about the whole For / Next loop. Any advise
or 'fix up' code will be greatly appreciated.
Here is all the code........
Private Sub Command12_Click()
Dim QueryNm As QueryDef
Dim TableNm As TableDef
Dim TempTable As TableDef
Dim TempTableName As String
Dim Indicator As String
Dim sqlstr As String
Dim X As Integer
Dim db As Database
Dim rst1 As Recordset
DoCmd.SetWarnings False
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
'********
With rst1
'********
Set rst1 = db.OpenRecordset("tblIMPORTUserFieldsTable", dbOpenTable)
.MoveFirst
Do Until .EOF
For Each QueryNm In .QueryDefs
If InStr(QueryNm.SQL, [rst1]) <> 0 Then
Indicator = "Found"
sqlstr = "INSERT INTO tbl_TempList(Name1) VALUES ('"
sqlstr = sqlstr & QueryNm.Name & "');"
DoCmd.RunSQL sqlstr
End If
Next QueryNm
rst1.MoveNext
Loop
'*******
End With
'*******
'*******
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
End Sub
should them look through the sql of each query in the db and see if the table
name is referenced. If so, it sets an indicator to true and writes that
query name to a separate table. It then searches for the remainder of the 30
or so tables. Here is the code. As of now I get a Compile error on the
line: For Each QueryNm In .QueryDefs. It says method or data member not
found. To be honest I am uneasy about the whole For / Next loop. Any advise
or 'fix up' code will be greatly appreciated.
Here is all the code........
Private Sub Command12_Click()
Dim QueryNm As QueryDef
Dim TableNm As TableDef
Dim TempTable As TableDef
Dim TempTableName As String
Dim Indicator As String
Dim sqlstr As String
Dim X As Integer
Dim db As Database
Dim rst1 As Recordset
DoCmd.SetWarnings False
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
'********
With rst1
'********
Set rst1 = db.OpenRecordset("tblIMPORTUserFieldsTable", dbOpenTable)
.MoveFirst
Do Until .EOF
For Each QueryNm In .QueryDefs
If InStr(QueryNm.SQL, [rst1]) <> 0 Then
Indicator = "Found"
sqlstr = "INSERT INTO tbl_TempList(Name1) VALUES ('"
sqlstr = sqlstr & QueryNm.Name & "');"
DoCmd.RunSQL sqlstr
End If
Next QueryNm
rst1.MoveNext
Loop
'*******
End With
'*******
'*******
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
End Sub