Compare Column Names & Sequence

ashley25

Registered User.
Local time
Today, 08:00
Joined
Feb 17, 2013
Messages
46
I want to be able to compare two tables to see whether their Column Names & sequence are the same.

Has anyone ever done this before?
 
You could adapt this code to fit your needs:

Code:
Public Function test()
Dim rs As Recordset
Dim rs1 As Recordset
Dim i As Integer
 
Set rs = CurrentDb.OpenRecordset("FirstRecordset")
Set rs1 = CurrentDb.OpenRecordset("SecondRecordset")
 
If rs.Fields.Count <= rs1.Fields.Count Then
    Debug.Print "1st recordset - 2nd recordset"
    For i = 0 To rs.Fields.Count - 1
        If rs.Fields(i).Name <> rs1.Fields(i).Name Then
            Debug.Print rs.Fields(i).Name & " - " & rs1.Fields(i).Name
        End If
    Next i
    
    If rs.Fields.Count <> rs1.Fields.Count Then
        For i = rs.Fields.Count To rs1.Fields.Count - 1
            Debug.Print "none - " & rs1.Fields(i).Name
        Next i
    End If
Else
    Debug.Print "2nd recordset - 1st recordset"
    For i = 0 To rs1.Fields.Count - 1
        If rs1.Fields(i).Name <> rs.Fields(i).Name Then
            Debug.Print rs1.Fields(i).Name & " - " & rs.Fields(i).Name
        End If
    Next i
    
    For i = rs1.Fields.Count To rs.Fields.Count - 1
        Debug.Print rs.Fields(i).Name & " - none"
    Next i
End If
End Function
 

Users who are viewing this thread

Back
Top Bottom