Getting name of attachment - Type mismatch

Hi

In my mail-in database, I am trying to read and process the name of an attachment(if any) in a ‘before new mail arrives’ agent.

Using the code below, a ‘type mismatch’ is returned on the forall statement. I have read similar problems on this forum earlier, but no one seem to have a solution. It should work, as the code is copied from the help file. Any ideas?

Sub Initialize

Dim session As New notessession

Dim currentdb As notesdatabase

Dim doc As NotesDocument

	

Set currentdb = session.CurrentDatabase

Set doc = session.DocumentContext





If doc.HasEmbedded Then

	Forall o In doc.EmbeddedObjects '<-This returnes 'Type mismatch'. Why?

		Messagebox( o.Name )

	End Forall

		

Else

	Messagebox "No embedded objects found"

End If

End Sub

Subject: Getting name of attachment - Type mismatch

Henrik,

Whereas HasEmbedded will tell you if a document contains Attachments, the EmbeddedObjects property of NotesDocument does NOT include file attachments - it only gives you “OLE/2 and OLE/1 embedded objects in a document” (from help). You have to use the EmbeddedObjects property of the NotesRichTextItem class to get file attachments, so you will need to get a handle on the Body field in the e-mail.

Hope this helps,

Emily.

Subject: Getting name of attachment - Type mismatch

Have you checked to see if it is Nothing first?

Subject: RE: Getting name of attachment - Type mismatch

Ok, tried it now. Now the ‘If doc.EmbeddedObjects Is Nothing Then’ line returns type mismatch…

If doc.EmbeddedObjects Is Nothing Then

		Messagebox "no embedded objects"

	Else

		Forall o In doc.EmbeddedObjects

			Messagebox( o.Name )

		End Forall

	End If

Subject: RE: Getting name of attachment - Type mismatch

The EmbeddedObjects property of the NotesDocument class must return an array for your loop to work properly. Use the isarray function to test before entering the loop.Sub Initialize

Dim session As New notessession

Dim currentdb As notesdatabase

Dim doc As NotesDocument

Dim varObjects as Variant



Set currentdb = session.CurrentDatabase

Set doc = session.DocumentContext

varObjects = doc.EmbeddedObjects

if isarray(varObjects) then

Forall o In varObjects

Messagebox( o.Name )

End Forall

Else

Messagebox “No embedded objects found”

End If

End Sub

If you just want to process attachments, evaluating the @AttachmentNames function might also work:

Sub Initialize

Dim session As New notessession

Dim currentdb As notesdatabase

Dim doc As NotesDocument

dim objAttchmnt as NotesEmbeddedObject

Dim varAttNames as Variant

Set currentdb = session.CurrentDatabase

Set doc = session.DocumentContext

varObjects = evaluate({@AttachmentNames}, doc)

if isarray(varAttNames) then

Forall attName In varAttNames

set objAttchmnt = doc.GetAttachment(attName)

if not(objAttchmnt is nothing) then

msgbox {Found an embedded object with a name “} & attName & {”}, , “Results . . .”

end if

End Forall

Else

Messagebox “No embedded objects found”

End If

End Sub

hth,

dgg

Subject: RE: Getting name of attachment - Type mismatch

Worked like a charm…Thanks alot, Dallas…