Function CompTable(NameSourceTBL As String, NameTargetTBL As String, NameIdField As String) As Byte
Dim raznicaECTb As Byte
Dim rst As DAO.Recordset
Dim fld As DAO.Field
Dim strNameTabl1 As String
Dim strNameTabl2 As String
Dim strIDName As String
strNameTabl1 = NameSourceTBL ' имя таблицы 1
strNameTabl2 = NameTargetTBL ' имя таблицы 2
strIDName = NameIdField ' имя ключевого поля
Set rst = CurrentDb.OpenRecordset("SELECT " & strNameTabl1 & ".*, " & strNameTabl2 & ".* FROM " & strNameTabl1 & " INNER JOIN " & strNameTabl2 & " ON " & strNameTabl1 & "." & strIDName & " = " & strNameTabl2 & "." & strIDName & ";")
With rst
If .RecordCount <> 0 Then
rst.MoveFirst
raznicaECTb = 0
Do While Not .EOF And raznicaECTb = 0
For Each fld In rst.Fields
If fld.SourceTable = strNameTabl1 Then
SysCmd acSysCmdSetStatus, "-" & Nz(fld.Value) & "-" & fld.Name
If fld.Value <> .Fields(strNameTabl2 & "." & fld.SourceField).Value Then
raznicaECTb = 1
Exit For
End If
End If
Next
Loop
End If
End With
CompTable = raznicaECTb
End Function
|