我有一份文件和文件副本。我使用TagNo作为两个文档的唯一ID。我还有Status字段来区分每个文档,包括Active,Inactive,Draft和Lock。我将在下面解释我的文件情况。
下面是我的文件,有两个字段;标签号= PTagNo;状态= PStatus。情况如下。
我粘贴我的保存代码如下。 保存并完成
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim activeDoc As NotesDocument
Dim view As NotesView
Dim keys(1) As String
'// Set database and doc
Set db = session.CurrentDatabase
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document
keys(0) = doc.PTagNo(0)
keys(1) = "Lock"
Set view = db.GetView("Computer")
vpswd = Inputbox$("Pls input code to save :")
If vpswd = "o" Then
Set activeDoc= view.GetDocumentByKey(keys, True)
If Not activeDoc Is Nothing Then
If activeDoc.PStatus(0) = "Lock" Then
activeDoc.DocumetId = doc.UniversalID
Call activeDoc.ReplaceItemValue("PStatus", "Inactive")
Call activeDoc.Save(True, False)
End If
End If
Call uidoc.FieldSetText("PStatus" , "Active")
Call uidoc.FieldSetText("SaveOptions" , "1")
Call uidoc.Save
Call uidoc.Close
Else
Msgbox "Wrong Code"
Exit Sub
End If
End Sub
所以我对字段ptagno使用GetDocumentByKey,但它显示错误“对象变量未设置”。我使用了错误的功能吗?任何帮助将不胜感激。谢谢!
变量ptagno尚未设置 - 因此“对象变量未设置”错误。您需要从字段PTagNo中读取值并将其分配给ptagno变量 - 或直接使用它。比如这样:
Set activeDoc= view.GetDocumentByKey(uidoc.FieldGetText("PTagNo"))