Embedobject and RT

Hi,

I,m trying to embed pdf-files to several notesdocument with an lotus script agent. But I get the “object variable not set” all the time. If I open the document and write something to the rich text field, save it and then remove the text and saving it again ,then my agent works fine. But if the document is “untouched” it won´t work. My agent is trigged by a button in a view. What have I missed,missunderstod? Here is my code:

Dim rtitem As NotesRichTextItem

Dim object As NotesEmbeddedObject

Dim path As String

Dim code As String

Dim fileend As String

Dim municipality As String

Set sess=New NotesSession

Set db=sess.CurrentDatabase

Set view=db.Getview(“vimport”)

path=Inputbox ( “Find the path?” , “Stat” , "h:\files" )

fileend=“.pdf”

Set doc=view.GetFirstDocument

While Not (doc Is Nothing)

Set rtitem=doc.GetFirstItem(“file”)

code=doc.mcode(0)

If Not doc.HasItem(“$File”) Then

Set object = rtitem.EmbedObject_

( EMBED_ATTACHMENT,“”, path+code+fileend)

Call doc.Save(True, False)

Else

Set object = rtitem.GetEmbeddedObject(code+fileend)

Call object.Remove

Set object = rtitem.EmbedObject _

( EMBED_ATTACHMENT,“”, path+code+fileend)

Call doc.Save(True, False)

End If

Set doc=view.GetNextDocument(doc)

Wend

thankfull for any help.

Carola

Subject: Embedobject and RT

Why not check (in your script) whether the the rich text item exists, and if not, create it.

Subject: Embedobject and RT

Replace:

Set rtitem=doc.GetFirstItem(“file”)

With:

Set rtitem = doc.CreateRichTextItem(“file”)

Actually there’s more to it than that:

Dim rtitem As NotesRichTextItem

Dim object As NotesEmbeddedObject

Dim path As String

Dim code As String

Dim fileend As String

Dim municipality As String

Set sess=New NotesSession

Set db=sess.CurrentDatabase

Set view=db.Getview(“vimport”)

path=Inputbox ( “Find the path?” , “Stat” , “h:\files" ) fileend=”.pdf"

Set doc=view.GetFirstDocument

While Not (doc Is Nothing)

'commenting this out

'Set rtitem=doc.GetFirstItem(“file”)

code=doc.mcode(0)

If Not doc.HasItem(“$File”) Then

   'item doesn't exist? - add this to create it -- your "obj. var. not set" error probably comes from here in the original - a real check would be doc.HasItem("file")

   Set rtitem = doc.CreateRichTextItem("file")

   Set object = rtitem.EmbedObject_

( EMBED_ATTACHMENT,“”, path+code+fileend)

Call doc.Save(True, False)

Else

   'add this

   Set rtitem = doc.GetFirstItem("file")

   Set object = rtitem.GetEmbeddedObject(code+fileend)

   Call object.Remove

   Set object = rtitem.EmbedObject _

( EMBED_ATTACHMENT,“”, path+code+fileend)

   Call doc.Save(True, False)

End If

Set doc=view.GetNextDocument(doc)

Wend

Good luck.

Subject: RE: Embedobject and RT

Thank you very much, my agent works perfectly now…:slight_smile: