Getting an error ----The document is not in the view "XYZ" ---Please help

Hi All,

I am using a view and getting the collection of documents

The collection come correct , but after the collection is over when I use

Set doc = view.getNextDocument(doc)

I get an error

“This documentis not in the view”

Here is my code:

Dim session As New notesSession

Dim workspace As NotesUIWorkspace

Dim db As NotesDatabase

Dim view As NotesView

Dim dc As NotesDocumentCollection

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim doc1 As NotesDocument



Set db = session.CurrentDatabase

Set view = db.getView("XYZ")



Set doc = view.GetFirstDocument

While Not doc Is Nothing

	Dim key1 As String

	If doc.SurveySupplier(0) <> "" Then

		key1 = doc.SurveySupplier(0) + " - " + doc.SAPID(0)

	Else

		key1 = doc.SupplierSiteName(0) + " - " + doc.SAPID(0)

	End If

	Set dc = view.GetAllDocumentsByKey(key1, True)

	If dc.count > 1 Then

		For i =1 To dc.count

			Set doc1 = dc.GetNthDocument(i)

			Set doc = doc1

			If Not doc1 Is Nothing Then

				

				If doc1.HasItem("PSW1") Then

					If doc1.PSW1(0) >= 0 Then

						

					Else

						doc1.PSW1 = 0

					End If

Else

				doc1.PSW1 = 0

End If

End If

Call doc1.Save(True, False)

Next i

Set doc = view.GetNextDocument(doc)

Wend

Please help ,

When I run in the Debug mode i get an error on line "Set doc = view.getNextDocument(doc)

Also I changed it to "Set doc = view.getnextDocument(doc1) and still gives me an error.

My view has many more documents for the While loop to end

Thanks in advance

ac ac

Subject: Getting an error ----The document is not in the view “XYZ” —Please help

My guess, is you’re changing the value of doc on the line ( Set doc = doc1 ). I think you really don’t want to do this but…

Then you’re making changes to doc1 which I’m guessing results in doc1 “disappearing” from the view. Given doc = doc1, doc also disappears from the view and you’re getting your error message.

As I don’t understand what you’re trying to do with your code, this is how I would overcome your problem with the code you supplied:

Set doc = view.GetFirstDocument

While Not doc Is Nothing

	Set nextDoc = view.GetNextDocument(doc)

	Dim key1 As String

	If doc.SurveySupplier(0) <> "" Then

		key1 = doc.SurveySupplier(0) + " - " + doc.SAPID(0)

	Else

		key1 = doc.SupplierSiteName(0) + " - " + doc.SAPID(0)

	End If

	Set dc = view.GetAllDocumentsByKey(key1, True)

	If dc.count > 1 Then

		For i =1 To dc.count

			Set doc1 = dc.GetNthDocument(i)

			Set doc = doc1

			Set nextDoc = view.GetNextDocument(doc)

			If Not doc1 Is Nothing Then

				

				If doc1.HasItem("PSW1") Then

					If doc1.PSW1(0) >= 0 Then

						

					Else

						doc1.PSW1 = 0

					End If

				Else

					doc1.PSW1 = 0

				End If

			End If

			Call doc1.Save(True, False)

		Next i

	End if ' Seemed to be missing

	' Remove Set doc = view.GetNextDocument(doc)

	Set doc = nextDoc

Wend

Subject: Getting an error ----The document is not in the view “XYZ” —Please help

Why do you have the line:

Set doc = doc1

it doesn’t appear to of any use. Remove that line and try again.