123FakeSt
IS-IT--Management
- Aug 4, 2003
- 182
I'm trying to complete a function that will create a report of any differences between two versions of the same database in terms of table structure.
It will report new or discontinued tables, and for tables that remain it will compare the tables field by field to make sure the fields and data types are consistent.
This is what I have so far. I was hoping someone would have a better idea so I don't end up having three databases open simultaneously to compare fields.
The early bird gets the worm, but the second mouse gets the cheese.
It will report new or discontinued tables, and for tables that remain it will compare the tables field by field to make sure the fields and data types are consistent.
This is what I have so far. I was hoping someone would have a better idea so I don't end up having three databases open simultaneously to compare fields.
Code:
Public Function CompareDatabaseTables(strDatabaseMaster As String, strDatabaseProtege As String) As String
Dim strSQL As String
Dim rst1 As ADODB.Recordset
Dim rst2 As ADODB.Recordset
Dim strReport As String
Set rst1 = New ADODB.Recordset
Set rst2 = New ADODB.Recordset
Dim db1 As DAO.Database
Dim tdf1 As DAO.TableDef
Dim fld1 As DAO.Field
Dim db2 As DAO.Database
Dim tdf2 As DAO.TableDef
Dim fld2 As DAO.Field
'Loop through all tables in the Master Database, for each table
strSQL = "SELECT * FROM msysobjects IN """ & strDatabaseMaster & """" & _
" WHERE type IN (1,6)"
rst1.Open strSQL, CurrentProject.Connection, adOpenDynamic, adLockReadOnly
If Not rst1.EOF Then
rst1.MoveFirst
Do Until rst1.EOF
'Check if the table exists in the Protege Database
strSQL = "SELECT * FROM msysobjects IN """ & strDatabaseProtege & """ WHERE type IN (1,6) AND name = """ _
& rst1!name & """"""
rst2.Open strSQL, CurrentProject.Connection, adOpenDynamic, adLockReadOnly
If rst2.EOF Then
'If not report it
strReport = rst!name & " does not exist in protege." & Chr(13)
Else
'If it does
rst2.MoveFirst
'Loop through all of the fields in the Master Table
'Check if the field exists in the Protege Database
'If not Report it
'If it does Compare the data types to see if they match
'If they do continue
'If they don't report it
'Loop through all of the fields in the Protege Table
'Check if the field exists in the master
'If it doesn't report it
'If it does continue
End If
rst2.Close
rst1.MoveNext
Loop
'Loop through all of the tables in the Protege Database, for each table
'Check if the table exists in the Master Database
'If not report it
'If it does continue
End If
Set rst1 = Nothing
End Function
The early bird gets the worm, but the second mouse gets the cheese.