If you create a ROLE e.g.[CanDel] in the ACL, you’ll be able to give each person the proper ROLE to either delete or not. In the database script you can decide based on that ROLE, who’ll be able to delete the specified form.
Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)
Editor/reader access you control from the form it self.
Continue = False
Dim sess As New NotesSession
Dim db As NotesDatabase
Dim ws As New NotesUIWorkspace
Dim Roller As Variant
Dim acl As NotesACL
Dim entry As NotesACLEntry
Roller = Evaluate("@UserRoles")
Set acl = db.ACL
Set entry = acl.GetEntry( sess.CommonUserName )
If ws.Currentdocument.document.Form(0) = "Form1" Then
If entry Is Nothing Then
Forall r In Roller
If ( r = "[CanDelete]" ) Then
If entry.IsRoleEnabled( "[CanDelete]" ) Then
Continue = True
Else
Continue = False
Exit Forall
End If
End If
End Forall
End If
End If
Call ws.ViewRefresh
1)The ws.CurrentDocument.Document is a NotesDocument. It doesn’t have Form(0) property. Should I use GetItemValue(“Form”) instead?
Error “Object variable not set” showed up when using ws.CurrentDocument.Document. Here is my code sample:
Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument.Document
Dim doc As NotesDocument
Set doc = uidoc.Document '<- Error Here!
Continue = False
A Notes document do always have the FORM field after it’s saved. But the problem in your code is that you try to set a document from a document. Your code should be like this:
Indeed, that was my typo mistake. However after rectifying it, the “Object variable not set” error still appear when I tried to delete a document from a view.It happened at the line: Set doc = uidoc.Document.
As in my example, I can see only “doc declaration successfully” message pop up when deletion.
Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument
If Isnull(uidoc) Then
Msgbox "uidoc is null"
End If
Dim doc As NotesDocument
Msgbox "doc declaration successfully"
Set doc = uidoc.Document <--Error Here!
Msgbox "set doc successfully"
If doc.Form(0) = "Form1" Then
Msgbox "Form 1!"
Else
Msgbox "Not Form 1"
End If
My mistake, sorry! But here is a script that works. The Source object returns Documentcollection.
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim coll As NotesDocumentCollection
Dim doc, doc2 As NotesDocument
Dim i As Integer
Set db = session.CurrentDatabase
If Source.Documents.Count > 0 Then
Set coll = Source.Documents
Set doc = coll.GetFirstDocument
For i = 1 To coll.Count
If Not doc Is Nothing Then
If doc.Form(0) = "Form1" Then
Set doc2 = doc '<-------- take care of the document sequence
Msgbox "Form 1!"
Continue = True
Else
Set doc2 = doc '<-------- take care of the document sequence
Msgbox "Not Form 1"
Continue = False
End If
End If
If i < coll.Count Then
Set doc = coll.GetNextDocument(doc2)
End If
Next
End If
Call ws.ViewRefresh