3
votes

I have a requirement where there is a document which has an attachment and when I click on a button, it opens a new form. This form must have that attachment in the rich text field. I have written the below code in the PostOpen event of the new form that opens up

    Set item1= tardoc.GetFirstItem("Comments")
    Set item= sourcedoc.GetFirstItem("Current_US")
    If Not item Is Nothing Then
        If item.Type = RICHTEXT Then
            Set rtitem = item
            If Not Isempty(rtitem.EmbeddedObjects) Then
                Forall fileItem In rtitem.EmbeddedObjects
                    If fileItem.Type = EMBED_ATTACHMENT Then
                        Call fileItem.ExtractFile(filepath _
                        & Cstr(fileItem.Name))
                        attFile = filepath & Cstr(fileItem.Name)
                        Call item1.EmbedObject( EMBED_ATTACHMENT, "", attFile)
                    End If
                End Forall
            End If 
        End If 
    End If

The sourcedoc is the doc from where the attachment has to be copied and the tardoc is the doc to which the attachment has to be copied and it is also the new document that opens up, so in the postopen event of this form I have written the code. But at this line the code fails saying object variable not set. Call item1.EmbedObject( EMBED_ATTACHMENT, "", attFile)

1

1 Answers

3
votes

The code won't work in Postopen event as it is too late for changing a rich text field.

Create the document in a button with back-end classes and open document for editing then.

Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim tardoc As NotesDocument
Dim item1 As NotesRichTextItem

Set tardoc = session.CurrentDatabase.CreateDocument
tardoc.Form = "YourForm"
Set item1= tardoc.CreateRichtextItem("Comments")
Set item= sourcedoc.GetFirstItem("Current_US")
If Not item Is Nothing Then
    If item.Type = RICHTEXT Then
        ... your code ...
    End If 
End If
Call workspace.EditDocument(True, tardoc)

As tardoc is a new document you have to create the target rich text field first

Set item1= tardoc.CreateRichTextItem("Comments")