Only one and of type gif or jpg/jpeg in this case.
Note : SaveOptions need to be taken care !!
Sub Click(Source As Button)
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim rtitem As Variant
Dim objName As String
Dim objExtn As String
Dim count1 As Integer
count1 = 1
'setting the doc to uidoc
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document
' validation for other mandatory fields
If ( uidoc.FieldGetText("tName")="") Then
Messagebox "Please enter Name",0,"Alert"
Call uidoc.GotoField("tName")
Exit Sub
End If
'. . . and so on
'setting save options to '0'
doc.SaveOptions="0"
Call uidoc.save
Call uidoc.reload
Set rtitem = doc.GetFirstItem( "rtFoto" )
'checking for whether anything has been attached or not
If (rtitem.Type = RICHTEXT And Isarray( rtitem.EmbeddedObjects) ) Then
Forall o In rtitem.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) Then
'capturing the attachment name and number of attachements
objName = o.name
count = count + 1
End If
End Forall
Else
var = workspace.Prompt(PROMPT_OK,"Alert","attach foto")
Call uidoc.GotoField("rtFoto")
Exit Sub
End If
'restricting the user to attach only one attachment
If(count<> count1) Then
var = workspace.Prompt(PROMPT_OK,"Alert","only one foto please")
Call uidoc.GotoField("rtFoto")
Exit Sub
Else
'restricting the user to attach only gif or jpg file
objExtn = Strright( objName, "." )
If Not (objExtn = "gif" Or objExtn = "jpg" Or objExtn = "jpeg") Then
var = workspace.Prompt(PROMPT_OK,"Alert","attach a 'gif' or a 'jpg' foto")
Call uidoc.GotoField("rtFoto")
Exit Sub
End If
End If
'finally saving the document
doc.SaveOptions="1"
Call uidoc.save
End Sub
This was first published in February 2002