我有两个视图,分别是计算机和草稿。我在计算机视图中创建一个按钮,该按钮是将计算机文档的副本创建到草稿视图。
下面是我的按钮代码。当我单击按钮时,它说“未设置对象变量”
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim view As NotesView
Set db = session.CurrentDatabase
Set view = db.GetView( "Draft" )
Set doc = dc.GetFirstDocument()
Set dc = db.AllDocuments
While Not (doc Is Nothing)
Call doc.CopyToDatabase(db)
Set doc = dc.GetNextDocument(doc)
Wend
End Sub
有人可以帮助我吗?我可以问一下,是否需要在“草稿”视图中插入任何公式?感谢您的帮助!
答案 0 :(得分:1)
视图不“包含”文档。文档位于数据库中,视图使用SELECT公式显示选定的文档。如果您的SELECT与所有文档匹配,则会显示所有文档。该公式决定了哪些文档是视图的一部分。
如果视图A包含您的文档,而视图B不包含文档,则必须在视图B中调整SELECT公式,以便它与文档匹配。
例如如果希望当前文档显示在视图B中,则可以向当前文档中添加一个值,例如DocumentViews,并将其设置为“ B”,然后将视图B的SELECT公式设置为SELECT DocumentViews =“ B”。
现在,如果要对视图中当前选定的文档执行某些操作,则可以使用NotesDatabase.UnprocessedDocuments属性。它包含所有选定文档的列表。
Dim ns As New NotesSession
Dim db As NotesDatabase
Set db= ns.CurrentDatabase
Dim dc As NotesDocumentCollection
Set dc= db.UnprocessedDocuments
Dim doc As NotesDocument
Set doc= dc.GetFirstDocument
Dim newdoc As NotesDocument
Do Until doc Is Nothing
' you might have to check the status of the current document before copying...
Set newdoc= doc.CopyToDatabase(db)
Call newdoc.ReplaceItemValue("Status", "Draft")
Call newdoc.Save(True, False)
Set doc= dc.GetNextDocument(doc)
Loop