Reputation: 3
This is probably something easy but I've been pounding my head against the wall trying to figure out what I'm doing wrong. The program is reading one document in a local db, getting a list stored in a field, looping through each entry in the list and searching for the name on a view in another db, once it finds it, it updates document and saves it. The problem I am seeing is that pdoc (bolded below) never gets set to a value which causes the rest of the program to fail to update any documents.
Sub Initialize
Dim db As NotesDatabase
Dim s As New NotesSession
Dim pview As NotesView
Dim ldoc As NotesDocument, pdoc As NotesDocument
Dim lgroup As Variant, pgroup As Variant, errors As Variant
Dim collection As NotesDocumentCollection
Dim nab As New NotesDatabase ("","")
Call nab.Open( "xxxx/xxx", "names.nsf" )
Set db = s.currentdatabase
Set collection = db.unprocesseddocuments
Set ldoc = collection.getfirstdocument
Set pview = nab.GetView ("gfmm")
While Not(ldoc Is Nothing)
On Error Resume Next
lgroup = ldoc.groups(0)
ForAll g In lgroup
**Set pdoc = pview.GetDocumentByKey( g )**
pgroup = pdoc.ListName(0)
If lgroup = pgroup Then
pdoc.GroupType = "0"
Call pdoc.Save(True, True)
Else
errors = errors + g
End If
End ForAll
ldoc.errors = errors
ldoc.status = "Complete"
Call ldoc.save(True, True)
Set ldoc = collection.getnextdocument(ldoc)
Wend
End Sub
Upvotes: 0
Views: 200
Reputation: 12060
The error is quite simple: lgroups is not an array but a scalar value. This line
lgroup = ldoc.groups(0)
Just gets the first value of the item groups in ldoc, not all values. Just change it to
lgroup = ldoc.groups
Then you will have an array that you can loop through. Same is true for pgroup a view lines below.
Upvotes: 1