这可能很容易,但是我一直在撞墙,试图找出我做错了什么。该程序正在读取本地数据库中的一个文档,获取存储在字段中的列表,循环浏览列表中的每个条目,并在另一个数据库中的视图上搜索名称,一旦找到它,它将更新文档并保存。我看到的问题是,pdoc(在下面标记)从未设置为一个值,该值导致程序的其余部分无法更新任何文档。
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
错误非常简单:lgroups不是数组,而是标量值。此行
lgroup = ldoc.groups(0)
仅获得ldoc中项目组的第一个值,而不是所有值。只需将其更改为
lgroup = ldoc.groups
然后,您将拥有一个可以循环通过的数组。下面的pgroup a视图线也是如此。