Hello all,
We have a .dbf table of employee home addresses and work locations. Every quarter we are supposed to receive an update for this table. What I need to do is compare changes in employee home address field and work location field between the original and the update.
Any suggestions on how to do this via ArcObjects?
thanks
Public Sub GetDifferencesInJoinedRecords()
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pFLayer As IFeatureLayer
Set pFLayer = pMxDoc.FocusMap.Layer(0) 'Get first layer
Dim pDisplayTable As IDisplayTable
Set pDisplayTable = pFLayer
If Not TypeOf pDisplayTable.DisplayTable Is IRelQueryTable Then
MsgBox "Feature Layer is not joined! Exiting Sub."
Exit Sub
End If
Dim pQF as IQueryFilter
Set pQF = New QueryFilter
' Add some type of SQL selection to compare your joined table. Test it first in the Select by Attributes dialog
pQF.Whereclause = "ParentTableName.MyField <> JoinTableName.MyField"
Dim pTableCursor As ICursor
Set pTableCursor = pDisplayTable.SearchDisplayTable pQF, False
Dim pRow As IRow
Set pRow = pTableCursor.NextRow
Dim pParentIndex As Long
pParentIndex = pDisplayTable.DisplayTable.Fields.FindField("ParentTableName.myField") ' Substitute the actual Parent Table Name and Field Name
If pParentIndex = -1 Then
MsgBox "ParentTableName.myField Field Not Found! Exiting Sub." ' Substitute the appropriate message.
Exit Sub
End If
Dim pJoinIndex As Long
pJoinIndex = pDisplayTable.DisplayTable.Fields.FindField("JoinTableName.myField") ' Substitute the real Join Table Name and Field Name
If pJoinIndex = -1 Then
MsgBox "JoinTableName.myField Field Not Found! Exiting Sub." ' Fix the Message for your data
Exit Sub
End If
Do Until pRow Is Nothing ' Keep your loop as tight as possible and do not do Dim statements inside of it.
' Do something in the loop
Debug.Print pRow.Value(pParentIndex) & " <> " & pRow.Value(pJoinIndex) ' report value of field in join table
Set pRow = pTableCursor.NextRow
Loop
Exit Sub