Problems with Embedded Objects and QuerySave

Hi,I have attachments contained in a rich text item.

Set oEmbedded = ortitem.EmbedObject ( EMBED_ATTACHMENT, “”, filename )

and users can see the attachments stored in document, with an action:

Set ortitem = odoc.GetFirstItem( “rtxt” )

If ( ortitem.Type = RICHTEXT ) Then

Forall o In ortitem.EmbeddedObjects

If ( o.Type = EMBED_ATTACHMENT ) Then

  Call o.ExtractFile("c:\" & o.Source )	

End If

End Forall

End If

My problem is when users try to save the document with the notes toolbar save action, and without closing the document they try save document again with my action “Save&Close”.

Save & close code:

Set uidoc = Espacio.CurrentDocument

Set odoc = uidoc.document

If odoc.HasEmbedded Then

odoc.SaveOptions = “0”

End If

Call odoc.Save(True,True)

Call uidoc.Refresh

If Not (odoc.HasEmbedded) Then uidoc.Save

Call uidoc.Close(True)

QuerySave:

If source.document.name(0)<>”” Then Call Source.Refresh Else Continue=False

If source.document.HasEmbedded Then

source.document.SaveOptions = “0”

End If

Call source.document.Save(True,True)

Call source.Refresh

I think what’s happening is that the user is attaching the file to the RTF in the frontend UI document, and it creates the $FILE item to store the attachment, but there isn’t the file itself in the RTF.

I think, I’m saving the backend document before the UI document is saved and changes to the UI document are not reflected in the backend document.

When I open the document again,there is an attachment in the document that’s not linked to in a RTF, and when users try to see the selected attachment, in the first line :

Forall o In ortitem.EmbeddedObjects

they get the error: “type mismatch”, because ortitem.EmbeddedObjects is empty

Any ideas, to resolve this problem?

Thanks in advance,

Subject: Problems with Embedded Objects and QuerySave

Not quite sure what you are trying to achieve here Sophia with the save and close etc.

What is wrong with:

@Command([FileSave);

@Command([FileCloseWindow])

I can see you have extract and attach code in buttons, but what are you trying to do when the user saves and closes? What has it got to do with the RT field?

Dave

Subject: RE: Problems with Embedded Objects and QuerySave

Thanks a lot for your help, David. But with

@Command([FileSave);

@Command([FileCloseWindow])

I had the same problem, so I tried to do it in a different way, with the action “Save & Close”.

I’ll try to explain the problem better:

Users create a document, where they have to fill in several text fields, and they have the posibility to attach.

Before saving document,if I has attached, I check document properties, and attachments are contained in my hidden rich text item and it has created the $FILE item which stores them.

If I save the document (with the Script action or @Command([FileSave)), and I close it, when I open the document again,there is an attachment in the document that’s linked to in my RTF, my richtextitem isn’t empty.It has been refreshed.

User can’t see the attachments,at bottom of my form, If he can see or delete it, he selects the name of attachments that he wants to see,selecting it from a radiobutton and does click in my action “See attachment”.

Set odb = osesion.CurrentDatabase

set ouidoc = owork.CurrentDocument

Set odoc = ouidoc.DocumenT

Set ortitem = odoc.GetFirstItem( “Rtxitem” )

If ( ortitem.Type = RICHTEXT ) Then

Forall o In ortitem.EmbeddedObjects

If ( o.Type = EMBED_ATTACHMENT ) Then

name = o.Source		

If odoc.radiobutton(0) = name Then

Call o.ExtractFile("c:\Temp\Temp\" & o.Source )					

End If	

End If

End Forall

End If

OpenFile = "c:\Temp\Temp" & name

Ret = ShellExecuteAny(GetDesktopWindow, “open”,OpenFile, Byval 0&, Byval 0&, SW_SHOWNORMAL)

Just this point it works fine. And If I do it before saving the doc,it works fine too.

The problem is when I want to do that after saving the document(with the Script action or @Command([FileSave)) without closing the doc.

I get an attachment in the document but that’s not linked to in my RTF, so I can’t asked for the attachment, doing “ForAll o in ortitem.EmbeddedObjects”, because It’s empty. I’ve resolve it, adding to my “See aTTACHMENT” code the line:

If ( ortitem.Type = RICHTEXT ) Then

If Not Isempty (ortitem.EmbeddedObjects) Then

…

Else

Dim objeto As notesEmbeddedObject

Set objeto = odocActual.GetAttachment(elemento)

Call objeto.ExtractFile("c:\Temp\Temp" & objeto.Source )

End If

End If

But what’s matter if user tries to save the document with the notes toolbar save action,(not closing it), and later does click in the code button:@Command(FileSave);@Command(FileCloseWindow])???

When I open the document again,there is an attachment in the document that’s not linked to in a RTF,my ortitem.EmbeddedObjects is empty, and I can see the attachment at the bottom of my form. If you click in “See attachment”, you get the error “type mismatch”.

I hope I’ve explained you better.Perhaps there is something wrong in my code, I don’t know.

In any case,Thank you very much.

Regards

Subject: Problems with Embedded Objects and QuerySave

Hi, Sophia:I have the same problem, when I attach to the document and save it without closing it, if I try to see the attacments,I get the same error, and I have checked that my richt text is empty,but it ha created a $File item to store the attachments.

I don’t Know the way to resolve it,…