Attachment not transferred

Hi,I have the below code which will take attachment form one document and attach it to the currently opened document.

Below is the code.

Sub Click(Source As Button)

'*****************************'

	'attach the base figure file's automatically..code transferred to a button..	

'*****************************

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument



Dim sess As New NotesSession

Dim db As NotesDatabase

Dim autoattachview As NotesView

Dim fdoclink_0 As NotesDocument



Dim item As NotesItem

Dim rti As NotesRichTextItem

Dim rti1 As NotesRichTextItem

Dim rti2 As NotesRichTextItem



Dim auto As String

Dim trackauto As String

Set uidoc=ws.CurrentDocument

Set doc=uidoc.Document



Set db=sess.CurrentDatabase



'auto=uidoc.FieldGetText("FigureFileUNID")

'trackauto=doc.trackautoattach_0(0)

' doc.trackautoattach_0=

'Msgbox auto

'Msgbox trackauto

If uidoc.EditMode=True Then

'	If auto<>trackauto Then

	If uidoc.FieldGetText("Status") <> "Released" Then

		Set rti = doc.GetFirstItem( "AttachFile")

		If uidoc.FieldGetText("AttachFile") <> "" Then

			Call doc.RemoveItem( "AttachFile" )

			Set rti = doc.CreateRichTextItem( "AttachFile")

		End If

		

		If uidoc.fieldgettext("FigureFileUNID") <> "" Then

			i = 0

			Set item=doc.GetFirstItem("FigureFileUNID")

			Set autoattachview=db.GetView("FigureFile")

			Forall values_0 In item.Values

				unid = Cstr(values_0)

					'Msgbox unid

				Set fdoclink_0 =autoattachview.GetDocumentByKey(unid)

			      	'Msgbox unid

				Set rti1=fdoclink_0.GetFirstItem("AttachFile")

				Set rti2=Doc.GetFirstItem("AttachFile")

				If rti2 Is Nothing Then

					Set rti2=Doc.CreateRichTextItem("AttachFile")

					'Set rti2=rti1.CopyItemToDocument(doc,autoattach_1)

					Call rti2.AppendRTItem(rti1)

					Call rti2.AddNewLine(1)

					Call doc.Save(True,True)

				Else

					Call rti2.AppendRTItem(rti1)

					Call rti2.AddNewLine(1)

					Call doc.Save(True,True)

					

				End If

			End Forall 

		End If

		'End If

	End If

End If

'doc.trackautoattach_0=doc.FigureFileUNID(0)

'Dim attach As String

'attach=doc.trackautoattach_0(0)

'Msgbox attach

End Sub

Now this code works on QueryClose and button also but the attachment is not visible. N if one see the doc properties then the documents property says that this doc do contain attachment. (in $FILE). And I have to keep this code on a button and not on queryclose.

What can be the problem? Please let me know.

Subject: RE: Attachment not transferred…

This may help: Front-end file attachments in LotusScript

Subject: Attachment not transferred…

first i want to say i didn’t really finish looking at your code coz i was confused by all the variables…

but, have you tried to use embeddedobject(plz look up the correct class name) class? file attachments are embedded objects of type attachments. File attachments dont really store in the rich text field… they store directly in the form.

if you already doing it. i am sorry for this post. :stuck_out_tongue: good luck!