Tuesday, 29 August 2017

Disable Double-Click and CTRL+E to Edit Documents Using LotusScript

In an old Notes Application I've been working on last week one of the requirements was to prevent that user were able through a double click or using CTRL + E to put a document in Edit Mode. In some old documentation I came across a solution that I had previously used in Notes applications to solve this problem. In this case I could quickly implement a solution by using some LotusScript in the Form Events Querymodechange and QueryOpen and an Action Button Edit (Document). In case I ever need this again I described the solution for myself in this blog post.

A. Form - Globals - Declarations
Initially, add in the Form Globals - Declarations the line below.

Dim EditAction As Boolean

B. Querymodechange
Next enter the following code in the Querymodechange Event of the Form.

Sub Querymodechange(Source As Notesuidocument, Continue As Variant)
If Not Source.EditMode And Not EditAction Then
Messagebox "You must use the Action Button Edit to Edit the document",64,"Edit " &_
Continue = False
End If
End Sub

C. Queryopen
Next enter the following code in the QueryOpen Event of the Form.

Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
If Not Isnewdoc Then
If Source.EditMode Then
Messagebox "This document cannot be opened in Edit mode",16,"Edit Document"
Continue = False
End If
End If
End Sub

D. Action Button Edit
To make sure a document can be edited enter the following code in the Action Button Edit on the Form.

Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
EditAction = True
'   Do your checks to make sure they can edit the document, then put it into Edit mode
ws.CurrentDocument.EditMode = True
EditAction = False
End Sub

When a user double clicks in a Form in Read Mode or using CTRL + E to try to put the document in Edit Mode the Message below will appear.

A nice and simple LotusScript solution.

No comments:

Post a Comment