Search code examples
lotus-notes

VBA: Document command not available error


Why do i get "Document command not available error" when i trying to execute an approve action for a form. Its like a flow of approval cycle. This error occurs only for the last approver. When clicked on approve by last approver this error occurs. and the document is not getting approved. And on rejecting a different error message like "Notesdocument-cannot locate field" occurs but the document is rejected on pressing Ok. Can anybody help me please. below is the code for approve action

Sub Click(Source As Button)
    Dim w As New notesuiworkspace
    Dim uidoc As notesuidocument
    
    Set uidoc = w.currentdocument
    process = True
    approveapplication
    gprocess = False

    uidoc.Save
    uidoc.Refresh
End Sub

and for reject action:

Sub Click(Source As Button)
    Dim w As New notesuiworkspace
    Dim uidoc As notesuidocument
    
    Set uidoc = w.currentdocument
    process = False
    rejectapplication
    gprocess = False
    
    uidoc.Save
    uidoc.Refresh
End Sub

The above action is fine for previous approvers. Please help


Solution

  • "Document command not available" error means you're trying to access or do something in the wrong mode. You need to check that you are in edit mode before you can call uidoc.save. Your Approve code should look like this.

    Sub Click(Source As Button)
        On Error GoTo errHandle
        Dim w As New notesuiworkspace
        Dim uidoc As notesuidocument
        Set uidoc = w.currentdocument
        If Not uidoc.EditMode Then
            uidoc.EditMode = TRUE
        End If
        process =True
        approveapplication
        gprocess = FALSE
        uidoc.Save
        
        Exit Sub
        errHandle:
        Messagebox Lsi_info(2) + ": Error " + Str(Err) + " - " + Error(Err) + ", at line " + Str(Erl)
        Exit Sub
    End Sub
    

    You shouldn't call uidoc.refresh after calling save or the user will most likely be prompted to save the document again on document close even when there are no changes. Check the notes designer help for information about uidoc.save and uidoc.editmode. Also, note the error handling, error handling will help you pinpoint problems like this.

    The "Reject" action problem may be occur if you're accessing a field not visible on the form. Again, add the error handling, and it will be alot easier to trouble shoot.