Boa tarde Fabio.
o Link é:
https://www.maximoaccess.com/t32058-resolvidosegundo-e-ultimo-bloco-de-cruzamento-e-preenchimento-de-tabela#222063e o modulo é o seguinte
Sub PreenchePtr()
'código criado por Alexandre Neves, do Fórum MaximoAccess '
Dim Rst As DAO.Recordset, Rst1 As DAO.Recordset, strPtr As String, ContaPtr As Integer
Set Rst = CurrentDb.OpenRecordset("SELECT * FROM Princ LEFT JOIN Fis ON Princ.Ptr=Fis.Ptr ORDER BY Princ.Ptr")
Do While Not Rst.EOF
If Rst.AbsolutePosition = 0 Then
strPtr = Rst("Princ.Ptr")
ContaPtr = 1
Else
If Rst("Princ.Ptr") = strPtr Then
ContaPtr = ContaPtr + 1
Else
If ContaPtr = 1 Then
Set Rst1 = CurrentDb.OpenRecordset("SELECT * FROM Princ WHERE Ptr='" & strPtr & "'")
Rst1.Edit
If Rst1("PtrAlt") = Rst1("Ptr") Then Rst1("Idp") = "M1" Else Rst1("Idp") = "B2"
Rst1.Update
Set Rst1 = CurrentDb.OpenRecordset("SELECT * FROM Fis WHERE Ptr='" & strPtr & "'")
If Not Rst1.EOF Then
Rst1.Edit
Rst1("Idp") = "M1"
Rst1.Update
End If
Else
Set Rst1 = CurrentDb.OpenRecordset("SELECT * FROM Princ WHERE Ptr='" & strPtr & "'")
Do While Not Rst1.EOF
Rst1.Edit
If Rst1("PtrAlt") = Rst1("Ptr") Then Rst1("Idp") = "B3" Else Rst1("Idp") = "I4"
Rst1.Update
Rst1.MoveNext
Loop
Set Rst1 = CurrentDb.OpenRecordset("SELECT * FROM Fis WHERE Ptr='" & strPtr & "'")
Do While Not Rst1.EOF
Rst1.Edit
Rst1("Idp") = "I3"
Rst1.Update
Rst1.MoveNext
Loop
End If
strPtr = Rst("Princ.Ptr")
ContaPtr = 1
End If
End If
Rst.MoveNext
Loop
Set Rst = Nothing
Set Rst1 = Nothing
CurrentDb.Execute "UPDATE Princ SET Idp='M0' WHERE Cnc like 'Dev*'"
CurrentDb.Execute "UPDATE Princ SET Idp='B1' WHERE Cnc like 'Sobr*'"
CurrentDb.Execute "UPDATE Fis SET Idp='I1' WHERE IsNull(Ptr) and Cnc='Sobra'"
CurrentDb.Execute "UPDATE Princ SET Idp='B2' WHERE PtrAlt<>Ptr and (Cnc like 'Dev*' or Cnc like 'Sobra*')"
CurrentDb.Execute "UPDATE Princ LEFT JOIN Fis ON Princ.PtrAlt=Fis.Ptr SET Princ.Idp='B2' WHERE Princ.Ptr<>Princ.PtrAlt and Fis.Idp='M1'"
CurrentDb.Execute "UPDATE Princ LEFT JOIN Fis ON Princ.PtrAlt=Fis.Ptr SET Princ.Idp='I4' WHERE Princ.Ptr<>Princ.PtrAlt and Fis.Idp='I3'"
End Sub