Save copy document and change status field for cop

2019-08-29 10:13发布

I have a document, and copy of document. I use TagNo as unique ID for both documents. I also have Status field to differentiate each document which is Active, Inactive, Draft, and Lock. I will explain below my document situation.

Below here are my document with two field; Tag No = PTagNo; Status = PStatus. The situation as below.

  1. For Original document, the status is set Active. When copy is created, Original document will change to Lock, And Copy document status change to Draft. (For this I already achieve.)

  2. After done editing, I will change status for Draft document and Original document. This happen when I save Draft document as "Complete". My Draft document will be Original document while my Original document will be Archived document. So for my Draft document, status will change to Active while Original Document, status will change to Inactive.(Not achieve yet).

tagno

I paste my save code as below.

Save and Complete

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

So I use GetDocumentByKey for field ptagno but it show error "Object variable not set". Did I use wrong function?. Any help will be appreciated. Thanks!

1条回答
趁早两清
2楼-- · 2019-08-29 10:44

The variable ptagno has not been set - therefore the "Object variable not set" error. You need to read the value from the field PTagNo and assign it to the ptagno variable - or use it directly. For instance like this:

Set activeDoc= view.GetDocumentByKey(uidoc.FieldGetText("PTagNo"))
查看更多
登录 后发表回答