I want to see if any of the values in Table 1 appear in any of the fields in table 2 (actually in every table in the db)
Table1
FieldA
XYZ
ABC
123
Table2
FieldX FieldY FieldZ
Jane 25
Tom 12 XYZ
Joe 15 123
The field names in Table2 DO NOT match those in Table1.
The values in Table1, FieldA may not be in Table2 at all.
When a value from Table1 is found in Table2, I want to write the name of the table it was found in and the name of the field to a table called tblDocumentorProjs.
My code is as follows, but it keeps writing the name of table to my documentor table, but this table does not contain a value from Table1. I think the sequence of my events is off.
Would someone mind helping me figure this out? Thanks!
==========================================================
Dim db As DAO.Database
Dim rsDoc As DAO.Recordset 'RS: tblDocumentorProj
Dim tdf As DAO.TableDef
Dim rsOuter As DAO.Recordset
Dim rsInner As DAO.Recordset
Dim rsOuterFld As DAO.Field
Dim rsInnerFld As DAO.Field
Dim rsInnerFldMatch As DAO.Field
Dim blnJ As Boolean '> than 1 if table contained projects
Dim K As Integer '# of tbls that contain project vals
Set db = CurrentDb
Set rsDoc = db.OpenRecordset("tblDocumentorProj")
Set frm = Forms("form1")
DoCmd.RunSQL ("DELETE tblDocumentorProj.* FROM "
"&_tblDocumentorProj;")
i = 0
K = 0
For Each tdf In db.TableDefs
i = i + 1
blnJ = False
Set rsOuter = db.OpenRecordset("HTEDTA_GM180AP")
Set rsInner = db.OpenRecordset(tdf.Name)
'OUTER LOOP BEGINS
rsOuter.MoveFirst
Do While Not rsOuter.EOF
Set rsOuterFld = rsOuter("[GMPROJ]")
'INNER LOOP BEGINS
On Error Resume Next
If Err = 3021 Then
'Nothing
Else
rsInner.MoveFirst
Do While Not rsInner.EOF
For Each rsInnerFld In rsInner
If rsOuterFld = rsInnerFld Then
blnJ = True
rsInnerFldMatch = rsInnerFld.Name
Else
blnJ = False
rsInnerFldMatch = rsInnerFldMatch
End If
Next rsInnerFld
rsInner.MoveNext
Loop
End If
'INNER LOOP ENDS
rsOuter.MoveNext
Loop
' OUTER LOOP ENDS
If blnJ = True Then
MsgBox "blnJ = " & blnJ
K = K + 1
With rsDoc
.AddNew
!tblName = tdf.Name
!fldname = rsInnerFldMatch
!modDate = Now()
!modUser = f_getUser()
.Update
End With
End If
Next tdf
'==========================================================
'Cleanup code, etc
Table1
FieldA
XYZ
ABC
123
Table2
FieldX FieldY FieldZ
Jane 25
Tom 12 XYZ
Joe 15 123
The field names in Table2 DO NOT match those in Table1.
The values in Table1, FieldA may not be in Table2 at all.
When a value from Table1 is found in Table2, I want to write the name of the table it was found in and the name of the field to a table called tblDocumentorProjs.
My code is as follows, but it keeps writing the name of table to my documentor table, but this table does not contain a value from Table1. I think the sequence of my events is off.
Would someone mind helping me figure this out? Thanks!
==========================================================
Dim db As DAO.Database
Dim rsDoc As DAO.Recordset 'RS: tblDocumentorProj
Dim tdf As DAO.TableDef
Dim rsOuter As DAO.Recordset
Dim rsInner As DAO.Recordset
Dim rsOuterFld As DAO.Field
Dim rsInnerFld As DAO.Field
Dim rsInnerFldMatch As DAO.Field
Dim blnJ As Boolean '> than 1 if table contained projects
Dim K As Integer '# of tbls that contain project vals
Set db = CurrentDb
Set rsDoc = db.OpenRecordset("tblDocumentorProj")
Set frm = Forms("form1")
DoCmd.RunSQL ("DELETE tblDocumentorProj.* FROM "
"&_tblDocumentorProj;")
i = 0
K = 0
For Each tdf In db.TableDefs
i = i + 1
blnJ = False
Set rsOuter = db.OpenRecordset("HTEDTA_GM180AP")
Set rsInner = db.OpenRecordset(tdf.Name)
'OUTER LOOP BEGINS
rsOuter.MoveFirst
Do While Not rsOuter.EOF
Set rsOuterFld = rsOuter("[GMPROJ]")
'INNER LOOP BEGINS
On Error Resume Next
If Err = 3021 Then
'Nothing
Else
rsInner.MoveFirst
Do While Not rsInner.EOF
For Each rsInnerFld In rsInner
If rsOuterFld = rsInnerFld Then
blnJ = True
rsInnerFldMatch = rsInnerFld.Name
Else
blnJ = False
rsInnerFldMatch = rsInnerFldMatch
End If
Next rsInnerFld
rsInner.MoveNext
Loop
End If
'INNER LOOP ENDS
rsOuter.MoveNext
Loop
' OUTER LOOP ENDS
If blnJ = True Then
MsgBox "blnJ = " & blnJ
K = K + 1
With rsDoc
.AddNew
!tblName = tdf.Name
!fldname = rsInnerFldMatch
!modDate = Now()
!modUser = f_getUser()
.Update
End With
End If
Next tdf
'==========================================================
'Cleanup code, etc