Type Mismatch When running detach agent

When running the below agent from the actions menu, I get an error of type mismatch on the line Forall o In rtitem.EmbeddedObjects. It does not error out always. Sometimes runs just fine. But, other times errors out. The Database it will need to run on has all types of attachments. From Tif to Gif, doc, xls all types. It seems not to like Tif files. Anyone have any ideas. The script is below.

Sub Initialize

Dim sess As New NotesSession

Dim db As NotesDatabase     

Dim view As NotesView     

Dim doc As NotesDocument

Dim rtitem As NotesRichTextItem          

Dim FilePresent As String             

Dim FileName As String                 

Dim sDir As String

Dim i As Integer

Dim path As String



i = Msgbox ("YES = Detach AND Remove" & Chr(13) & Chr(13) & "NO = Detach but don't remove" & Chr(13) & _

Chr(13) & "CANCEL = I was joking, do nothing!",35,"Remove attachments?")

'Ask whether remove attachments or not

'If user chooses CANCEL then exit program

If i = 2 Then

Exit Sub

End If

'Check for the presence of destination folders and creates them if missing;

sDir = Dir$("C:/ReceivedFiles",16)

If sDir = "" Then

	Mkdir "C:/ReceivedFiles"

End If



sDir = Dir$("C:/SentFiles",16)

If sDir = "" Then

	Mkdir "C:/SentFiles"

End If



sDir = Dir$("C:/OtherFiles",16)

If sDir = "" Then

	Mkdir "C:/OtherFiles"

End If

'---------------------------------------------------------

Set db = sess.CurrentDatabase

Set view = db.GetView("($All)")

Set doc = view.GetFirstDocument     



Do Until doc Is Nothing

	If doc.HasEmbedded Then          'Checks for presence of embedded objects

If doc.HasItem(“DeliveredDate”) Then

path = “C:/ReceivedFiles”

Else

If doc.HasItem(“POSTEDDATE”) Then

path = “C:/SentFiles”

Else

path = “C:/OtherFiles”

End If

End If

Set rtitem = doc.GetFirstItem(“Body”)

Forall o In rtitem.EmbeddedObjects

If ( o.Type = EMBED_ATTACHMENT ) Then

				FileName = o.Source                         

FilePresent = Dir$(path & FileName,0)

'If current filename is already present in the directory then renames the destination file and checks again

If FilePresent <> "" Then                            

					Do Until FilePresent = ""                         

FileName = "c_ " & FileName

FilePresent = Dir$(path & FileName,0)

Loop

End If

Call o.ExtractFile(path & FileName )

Print "Extracting " & o.Source

'If user pressed YES in the initial msgbox then removes attachments

If i = 6 Then

					Call o.Remove

Call doc.Save( False, True )

End If

End If

End Forall

End If

Set doc = view.GetNextDocument(doc)

Loop

End Sub

Subject: Type Mismatch When running detach agent

Check the Rich Text field of the document in which it is erroring out for its content. If there is no embedded object in that field of a particular document, it will error out. Check if the field contains just Text, instead of an attachment. In this case, one can validate the rich text field and then process it, if there is any attachment of any type.

Note → .HasEmbeddedobjects, checks if there are attachments in the documents but not in this field.

Note—> Embedded objects and object links are not supported for OS/2, UNIX, and the Macintosh. File attachments are.

One can validate the rich text field for an empty field as follows:

Dim rtnav As NotesRichTextNavigator

Dim rt As Variant

Set rt = doc.GetFirstItem(“Body”)

if not rt is nothing then

Set rtnav = rt.CreateNavigator

If (rtnav.FindFirstElement(RTELEM_TYPE_DOCLINK) Or _

rtnav.FindFirstElement(RTELEM_TYPE_FILEATTACHMENT) Or _

rtnav.FindFirstElement(RTELEM_TYPE_OLE)) Or _

rtnav.FindFirstElement(RTELEM_TYPE_SECTION) Or _

rtnav.FindFirstElement(RTELEM_TYPE_TABLE) Or _

rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL) Or _

rtnav.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH) Or _

rtnav.FindFirstElement(RTELEM_TYPE_TEXTRUN) Then

foundContent = True

Else

foundContent = False

End If

End if

You can remove irrelavant things from above code and use the appropriate attachment related ones to find an attachment and process it.

Hope this helps a bit.