Check attachment size before doc is saved

Use the following code in the Querysave event to prevent saving a document that exceeds size limits you want to impose.

To avoid getting an extra prompt to save the document when the limit is exceeded, you'll either want to use the formula "@If(@Command([FileSave]);@Command([FileCloseWindow])" or use a hidden, editable "SaveOptions" field on the form, with a default text value of "1". If you use the SaveOptions field, then enable the "fieldsettext" calls in the script below.

Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim totalSize As Long

Set uidoc = ws.CurrentDocument
Set doc = uidoc.document

Call uidoc.refresh(True)
Dim rtitem As Variant
Dim embedObjs As Variant

Set rtitem = doc.getFirstItem("Body")
embedObjs = rttem.embeddedObjects
totalSize = 0
dim oneMB as long
oneMB = 1048576

If Not Isempty(embedObjs) Then
 For i = 0 To Ubound(embedObjs)
  totalSize = totalSize + embedObjs(i).
  If embedObjs(i).filesize > 2 * oneMB 
     Msgbox("Your attachment '"  +
embedObjs(i).name +"' is " +Cstr(Round
     (embedObjs(i).filesize / oneMB,1)) +"    
mb. The limit is 2.0 mb.")
     continue = False
     'Call uidoc.fieldsettext
   End If

 If totalSize > 4 * oneMB Then
    Msgbox("Your total attachment size is " 
+Cstr(Round (totalSize /
    oneMB,1)) +" mb.  The limit is 4.0 mb.")
    continue = False
    'Call uidoc.fieldsettext("SaveOptions","0")
  End If
End If

This was first published in February 2003

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.