Getnextentry not getting set

Hello,

I don’t know what is wrong in following code. I am checking if viewentrycollection is having more than 1 documents than get each entry from a view entry collection and send an email. But some how my next entry is not getting set. If I have 2 documents in view entry collection it sends an email to first entry 2 times, because getnext entry is not properly setting the next entry. Can any one guide me how to set next entry? Following is the code.

Sub Mail ( req As NotesDocument )

Dim view1 As NotesView

Dim dc As NotesDocumentCollection

Dim vc As NotesViewEntryCollection

Dim doc1 As NotesDocument

Dim entryOne As NotesViewEntry

Dim entryTwo As NotesViewEntry

Set view1 = db.GetView("lookupview")	

Dim j As Integer

Set vc = view1.AllEntries

query$ = req.product(0)

j = view1.FTSearch(query$, 0 )	

Set vc = view1.GetAllEntriesByKey(req.product(0))

j1 = vc.Count

If ( vc.Count >= 1 ) Then		

	For i = 1 To vc.Count 

		Set entryOne = vc.GetFirstEntry()

		Set doc1 = entryOne.Document	

		Dim taskowner, projname As Variant	

		Dim email As NotesDocument	

		Dim docCreator As String

		Set email = New NotesDocument( db )		

		Dim bodyItem As NotesRichTextItem

		Set bodyItem = email.CreateRichTextItem( "Body" )		

		Call bodyItem.AppendText( "" & doc1.CMH_FName(0) & "," )

		email.Form = "Memo"

		email.SendTo = taskowner

		email.Subject = req.Subject(0)

		email.SaveMessageOnSend = False						

		email.Send( False )				

		Call req.Save( False, True )			

		Set entryone = vc.GetNextEntry(entryone)

	Next i

End If

End Sub

Thanks

MS

Subject: try this

…If ( vc.Count >= 1 ) Then

Set entryOne = vc.GetFirstEntry()

For i = 1 To vc.Count

Set doc1 = entryOne.Document

…

Set entryone = vc.GetNextEntry(entryone)

Next i

Subject: a better way

Using for … next is not a good way to handle collections. Here’s my suggestion

Set entryOne = vc.GetFirstEntry()

Set doc1 = entryOne.Document

While Not (doc1 is Nothing)

… do your logic

… Set entryOne = vc.GetNextEntry(entryOne)

… Set doc1 = entryOne.Document

Wend

Apart from other benefits, this means you don’t have to check the number of entries in the collection, just do the loop.

If you are updating documents inside the loop, then GetNextEntry has problems knowing which is the next entry, you should then create a second object to store the NextEntry before you do the update, and set entryOne to the stored object at the end of the loop.

Subject: getnextentry not getting set

Thanks for your guidance. I actually tried that. You can see in my code, but some how it did not work.

Any way I found the other solution, and got it work. but based upon my study in this forum it looks like viewentrycollection has a problem.

Thanks again for your time.

MS