Codes doesn't look for correct key to match

The following is the sample codes I did. I want to create a button in a form (doc), and this button suppose to change a field value (MyField) in all response forms (rpdoc) that match a specific key (“ABC”). But when I run this codes, the system will change the field (MyField) in ALL response forms regardless whether it match the key (“ABC”) or not. Can anyone tell me where goes wrong with this codes?

Dim view As NotesView

Set view = db.GetView(“MyView”)

Dim ABC As String

ABC = uidoc.FieldGetText(“MyKey”)

Dim entry As NotesViewEntry

Set entry = view.GetEntryByKey(ABC, True)

Dim rpdoc As NotesDocument

Set rpdoc = entry.Document

Set nav = view.CreateViewNav()

Set entry = nav.GetFirstDocument

While Not(entry Is Nothing)

Set rpdoc = entry.Document

If doc.GetItemValue(“MyField”)(0) <> “” Then

  rpdoc.MyField = doc.MyField

End If

Call rpdoc.Save(True, True)

Set entry = nav.GetNextDocument(entry)

Wend

Thanks.

Subject: RE: Codes doesn’t look for correct key to match

Um, because you get a viewnav containing all the docs in the view, and then loop through and assign them all? Just because you have at one point in the past looked up a key in that view, doesn’t prevent you from accessing any other documents later.

Maybe you should use GetAllDocumentsByKey and StampAll.

Subject: RE: Codes doesn’t look for correct key to match

I have found the solution for my codes. Anyway, thanks for your suggestion.