W
William Benson
Hello folks,
I wrote a procedure for comparing queries in 2 different databases (part of
a version control strategy) and *thought* it would be a slam dunk to test
the queries in DB1 for existence in DB2, and of those which existed, test
that they both had the same field names. Apparently the line below
For Each
F1 In Q1.Fields
is not working out. Any idea why? Thanks if so...
Sub CompareDB()
Dim WS As Workspace
Dim DB1 As Database
Dim DB2 As Database
Dim Q1 As QueryDef
Dim Q2 As QueryDef
Dim F1 As Field
Dim F2 As Field
Dim FldFound As Boolean
Dim QFound As Boolean
Dim Msg As String
' Create a new Microsoft Jet workspace.
Set WS = CreateWorkspace("NewJetWorkspace", "admin", "", dbUseJet)
Const DB1_Path As String = "c:\DB1.mdb"
Const DB2_Path As String = "c:\DB2.mdb"
Set DB1 = WS.OpenDatabase(DB1_Path)
Set DB2 = WS.OpenDatabase(DB2_Path)
For Each Q1 In DB1.QueryDefs
QFound = False
For Each Q2 In DB2.QueryDefs
If Q1.Name = Q2.Name Then
QFound = True
If Q2.Fields.Count <> Q1.Fields.Count Then
Msg = Msg & " | " & "FIELD COUNT differs"
End If
For Each F1 In Q1.Fields
FldFound = False
For Each F2 In Q2.Fields
If F1.Name = F2.Name Then
FldFound = True
Exit For
End If
Next F2
If Not FldFound Then
If InStr(Msg, " " & Q1.Name & " ") = 0 Then
Msg = Msg & " | " & Q1.Name & " "
End If
Msg = Msg & " | " & "FIELD " & F1.Name & " NOT FOUND"
End If
Next F1
Exit For
End If
Next Q2
If Not QFound Then
Msg = Msg & " | QUERY " & Q1.Name & " NOT FOUND"
End If
Next Q1
If Msg <> "" Then Msgbox Msg
End Sub
I wrote a procedure for comparing queries in 2 different databases (part of
a version control strategy) and *thought* it would be a slam dunk to test
the queries in DB1 for existence in DB2, and of those which existed, test
that they both had the same field names. Apparently the line below
For Each
F1 In Q1.Fields
is not working out. Any idea why? Thanks if so...
Sub CompareDB()
Dim WS As Workspace
Dim DB1 As Database
Dim DB2 As Database
Dim Q1 As QueryDef
Dim Q2 As QueryDef
Dim F1 As Field
Dim F2 As Field
Dim FldFound As Boolean
Dim QFound As Boolean
Dim Msg As String
' Create a new Microsoft Jet workspace.
Set WS = CreateWorkspace("NewJetWorkspace", "admin", "", dbUseJet)
Const DB1_Path As String = "c:\DB1.mdb"
Const DB2_Path As String = "c:\DB2.mdb"
Set DB1 = WS.OpenDatabase(DB1_Path)
Set DB2 = WS.OpenDatabase(DB2_Path)
For Each Q1 In DB1.QueryDefs
QFound = False
For Each Q2 In DB2.QueryDefs
If Q1.Name = Q2.Name Then
QFound = True
If Q2.Fields.Count <> Q1.Fields.Count Then
Msg = Msg & " | " & "FIELD COUNT differs"
End If
For Each F1 In Q1.Fields
FldFound = False
For Each F2 In Q2.Fields
If F1.Name = F2.Name Then
FldFound = True
Exit For
End If
Next F2
If Not FldFound Then
If InStr(Msg, " " & Q1.Name & " ") = 0 Then
Msg = Msg & " | " & Q1.Name & " "
End If
Msg = Msg & " | " & "FIELD " & F1.Name & " NOT FOUND"
End If
Next F1
Exit For
End If
Next Q2
If Not QFound Then
Msg = Msg & " | QUERY " & Q1.Name & " NOT FOUND"
End If
Next Q1
If Msg <> "" Then Msgbox Msg
End Sub