|
|
Put one of these techniques in the QueryDocumentDelete Event:
Stop all deletions if any documents have children
Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)
Dim docsDelete As NotesDocumentCollection
Dim docsChildren As NotesDocumentCollection
Dim doc As NotesDocument
Dim i%
Set docsDelete = Source.Documents ' Selected documents
' Check selected documents for children
For i = 1 To docsDelete.Count
Set doc = docsDelete.GetNthDocument( i )
Set docsChildren = doc.Responses
' If children then cannot continue
If docsChildren.Count > 0 Then
Msgbox "Some of the selected documents have responses." + Chr(13) "No deletions were made."
Continue = False
Exit Sub
End If
Next
' No children found - OK to delete
Continue = True
End Sub
Prompt for user to continue if some documents have children
Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)
Continue = False ' deletions will be done by this script, so don't let Notes do it
Set docsDelete = Source.Documents ' Selected documents
' Check documents first
For i = 1 To docsDelete.Count
Set doc = docsDelete.GetNthDocument( i )
Set docsChildren = doc.Responses
If docsChildren.Count > 0 Then
cHaveChildren = cHaveChildren + 1
Else
cDelete = cDelete + 1
End If
Next
If cHaveChildren > 0 Then
msg = msg & Chr(13) & Cstr( cHaveChildren) & " document(s) have responses and will not be deleted." & Chr(13)
End If
msg = msg & Chr(13) & "Do you wish to continue?"
If Msgbox( msg, MB_YESNO+MB_ICONQUESTION, "Confirm Deletion" ) = IDYES Then
For i = 1 To docsDelete.Count
Set doc = docsDelete.GetNthDocument( i )
Set docsChildren = doc.Responses
If docsChildren.Count = 0 Then
Call doc.Remove( True )
End If
Next
' No way to refresh view here, so prompt user to press [F9] to refresh view
MsgBox("Press F9 to refresh view")
End If
End Sub