Notes Error: Error not foun in index

Guys i’m having a error “Notes Error: Error not foun in index” i created an agent which replaces the values in the documenthere’s the code:

Dim session As NotesSession

Dim uiw As New NotesUIWorkspace

Dim uiview As NotesUIView

Dim view As NotesView

Dim doc As NotesDocument

Dim formula As String

Dim item As NotesItem	

Dim one As String

Dim two,choice,server,datab,salesman,salesmanNum As String

Dim ct As Integer

Dim picklist As Variant

Dim messagelist As String

Dim dateonly As New NotesDateTime("")

Set uiview = uiw.CurrentView

Set view = uiview.View

Set session = New NotesSession

Set db  = session.CurrentDatabase	

Set doc = view.GetFirstDocument

choice = session.GetEnvironmentString("SalesChoice")

salesman = session.GetEnvironmentString("Salesman")

salesmanNum = session.GetEnvironmentString("SalesmanNum")

formula = |SELECT ((Form = "sales v2.0" &  try="| & choice & |"))|

Msgbox (formula)

'formula = |SELECT ((Form = "sales v2.0" &  cust_name2 ="002493"))|

view.SelectionFormula = formula

Call uiw.ViewRebuild

dateonly.LSLocalTime = Now

'Loop for replacing value

Do While Not (doc Is Nothing)

	Set item = doc.ReplaceItemValue("zCust_2",doc.GetFirstItem("zCust2"))

	Set item = doc.ReplaceItemValue("zCommod_2",doc.GetFirstItem("zCommod2"))		

	Set item = doc.ReplaceItemValue("zSrep_2",doc.GetFirstItem("zSrep2"))		

	Set item = doc.ReplaceItemValue("DateEffective_2",doc.GetFirstItem("DateEffective2"))

	Set item = doc.ReplaceItemValue("salesman2",salesman)	

	Set item = doc.ReplaceItemValue("zSrep2",salesman)

	Set item = doc.ReplaceItemValue("try",salesmanNum)

	Set item = doc.ReplaceItemValue("DateEffective2",dateonly.DateOnly)		

	

	Call doc.Save		(True,True)

	

Set doc = view.GetNextDocument( doc )

	

Loop







ct = view.EntryCount

Call session.SetEnvironmentVar( "count", ct )	

Messagebox ("The number of docs in this view = " &	ct &","&"Count of docs in view")

End Sub

the error is caused by “Set doc=view.GetNextDocument( doc )”

Subject: You must rethink your design approach.

A design that modifies itself at runtime isn’t practical, in part because you don’t want to have to give end users Designer access to your application.

There are several different ways to locate documents that meet certain criteria. Creating or modifying a view for each search is not on that list. Since all you really need in this case is a simple keyed lookup, have one view that lists all the target documents sorted by the cust_name2 field, and use GetAllDocumentsByKey to locate the matching set.

To answer the exact question you asked: the reason you’re getting Entry not found in index error message, is that you’re asking for the “next” document of a document that’s not in the view anymore once you change the selection formula. How is it supposed to answer that? Who was the next U.S. president after Neil Armstrong?

Subject: Thanks for the tip

I already redo my approach,your tip has help me realize my error :smiley: