Public Function UpdateErr()
Dim oldVal As String
Dim oldOrg As Long
Dim oldID As Long
Dim varBookmarkS As Variant
Dim flgID As Boolean
Dim strID As String
With CurrentDb.OpenRecordset("SELECT Val, Org, ID, IDError FROM Исходная ORDER BY Val, Org, ID")
Do Until .EOF
flgID = True
oldVal = .Fields(0)
oldID = .Fields(2)
If .Fields(1) = 1 Then
varBookmarkS = .Bookmark
Do While oldVal = .Fields(0) And flgID
flgID = flgID And oldID = .Fields(2)
.MoveNext
If .EOF Then Exit Do
Loop
.Bookmark = varBookmarkS
If flgID Then
.Edit
.Fields(3) = Null
.Update
.MoveNext
Do While oldVal = .Fields(0)
.Edit
.Fields(3) = 2
.Update
.MoveNext
If .EOF Then Exit Do
Loop
Else
oldID = .Fields(2)
strID = CStr(oldID) & ";"
.Edit
.Fields(3) = 1
.Update
.MoveNext
Do While oldVal = .Fields(0)
.Edit
If UBound(Filter(Split(strID, ";"), CStr(.Fields(2)), True)) > -1 Then
.Fields(3) = 2
Else
.Fields(3) = 1
oldID = .Fields(2)
strID = strID & CStr(oldID) & ";"
End If
.Update
.MoveNext
If .EOF Then Exit Do
Loop
End If
Else
Do While oldVal = .Fields(0)
oldOrg = .Fields(1)
flgID = True
oldID = .Fields(2)
varBookmarkS = .Bookmark
Do While oldVal = .Fields(0) And oldOrg = .Fields(1) And flgID
flgID = flgID And oldID = .Fields(2)
.MoveNext
If .EOF Then Exit Do
Loop
.Bookmark = varBookmarkS
If flgID Then
.Edit
.Fields(3) = Null
.Update
.MoveNext
Do While oldVal = .Fields(0) And oldOrg = .Fields(1)
.Edit
.Fields(3) = 2
.Update
.MoveNext
If .EOF Then Exit Do
Loop
Else
oldID = .Fields(2)
.Edit
.Fields(3) = 1
.Update
.MoveNext
Do While oldVal = .Fields(0) And oldOrg = .Fields(1)
.Edit
If oldID = .Fields(2) Then
.Fields(3) = 2
Else
.Fields(3) = 1
oldID = .Fields(2)
End If
.Update
.MoveNext
If .EOF Then Exit Do
Loop
End If
If .EOF Then Exit Do
Loop
End If
Loop
.Close
End With
End Function
|