Comparing Access database tables

What we have is two databases on seperate CD's, within those databases are tables that we need to compare from one database CD to the other database CD.  The column headings match, we are trying to see the differences in the data in each individual field between the two database tables.  Are there any tools that may accomplish this I have tried to search for some and have actually tried ones out, but they were unsuccessfull.  Any help on this would be great thankyou
Who is Participating?
culminITConnect With a Mentor Commented:
If its only the two tables you want to compare to each other, I would recommend firstly creating 2 outer join queries to check for non-existence on both sides:
SELECT Table1.* FROM Table1 LEFT JOIN Table2 ON Table1.CommonField = Table2.CommonField WHERE Table2.CommonField Is Null;
SELECT Table2.* FROM Table1 RIGHT JOIN Table2 ON Table1.CommonField = Table2.CommonField WHERE Table1.CommonField Is Null;
For differences on the matched inner join, you can do the following:
Create a new table (eg. tmp) with a field for the fieldname (FieldName), Value in table 1 (OldValue) and table 2 (NewValue).  Then you can try and use the code snippet I attached.
Hope that helps!  

Public Sub CompareData()
  Dim rstCompare As Recordset, rstDifferences As Recordset
  Dim iRecordNum As Long, sField As String
  Dim iFieldNum As Integer, sName As String
  Dim OldValue As Variant, NewValue As Variant
  On Error GoTo ErrHandler
  Set rstCompare = CurrentDb.OpenRecordset("SELECT * FROM Table1 INNER JOIN Table2 ON Table1.CommonField = Table2.CommonField;", dbOpenSnapshot)
  Set rstDifferences = CurrentDb.OpenRecordset("tmp", dbOpenDynaset)
    iRecordNum = 0
    With rstCompare
      If Not .EOF Then
        While Not .EOF
          iRecordNum = iRecordNum + 1
          For iFieldNum = 0 To .Fields.Count - 1
            sField = .Fields(iFieldNum).Name
            'Change this length to match your first table name
            If Left(sField, 7) = "Table1." Then
              sName = Right(sField, Len(sField) - 7)
              ' Columns to ignore
              If sName <> "CommonField" Then
                OldValue = .Fields("Table2." & sName)
                NewValue = .Fields(sField)
                If IsNull(OldValue) Then OldValue = "Null"
                If IsNull(NewValue) Then NewValue = "Null"
                If OldValue <> NewValue Then
                    rstDifferences!FieldName = sName
                    rstDifferences!OldValue = OldValue
                    rstDifferences!NewValue = NewValue
                End If
              End If
            End If
      End If
    End With
    'Clean up recordsets
    Set rstCompare = Nothing
    Set rstDifferences = Nothing
  On Error GoTo 0
  Exit Sub
  'Add some error handling
  Resume Next
End Sub

Open in new window

How many fields are you looking to compare from each table? Im sure someone will post some handy code for you to use, but I have done this on a relatively small scale using the conditional formatting features. This would assume you could get both tables into one file.  Example:

Table 1
Employee ID
First Name
Last Name

Table 2
Employee ID
First Name
Last Name

Make a query with Employee ID then pull each field from both tables. In essence you end up with a query that has the unique identifier and then both data items for each field. You can then go into the conditional formatting and write syntax like IF Table2. First Name is not equal to Table1. First Name turn it red. If you write that for each of your fields it will essentially highlight everywhere that the tables differ in data.

As I said if you are looking at comparing a lot of field this may not be a feasable option due to time, but it workss OK on a small scale

Are you looking for a way to automatically run through the tables and compare the data?  This process can be simplified if you can guarantee that the fieldnames match 100%, and there is always one common field that you expect the data to be the same (eg. the unique ID or code).
If this is the case, you can loop through the table definitions of one database.  Create a select that joins the two tables on the common field, then loop through the other fields and compare the two tables.  You will also need to do left and right joins where the records don't exist in one or the other.
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to and use offer code ‘EXPERTS’ to get 10% off your first purchase.

PvteyeAuthor Commented:
There are 40 or so field headings and about 190,000 lines of data to be compared, not sure if an automated tool would be better for this or some sort of code for joining the tables and things like that?
I'm sorry to bring up this PAQ's question, but I am also attempting to do the same and follow the same solution... I'm just not sure what is meant by:
"Create a new table (eg. tmp) with a field for the fieldname (FieldName), Value in table 1 (OldValue) and table 2 (NewValue).  Then you can try and use the code snippet I attached."

I have done both check queries (outer joins), and no queries have been returned.
Nevermind, I figured it out... just had to read the code to understand.. :)
Thanks for the solution.
No problem, glad it helped.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.