将附件从一个表单复制到另一个表单

时间:2016-12-01 07:01:29

标签: lotus-notes lotusscript

我有一个要求,其中有一个带有附件的文档,当我点击一个按钮时,它会打开一个新表单。此表单必须在富文本字段中具有该附件。我在打开的新表单的PostOpen事件中编写了以下代码

    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

sourcedoc是必须复制附件的文档,tardoc是必须复制附件的文档,它也是打开的新文档,因此在此表单的postopen事件中写了代码。但是在这一行,代码无法说明没有设置对象变量。 调用item1.EmbedObject(EMBED_ATTACHMENT,"",attFile)

1 个答案:

答案 0 :(得分:3)

代码在Postopen事件中不起作用,因为更改富文本字段为时已晚。

在带有后端类的按钮中创建文档,然后打开文档进行编辑。

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)

由于tardoc是一个新文档,您必须先创建目标富文本字段

Set item1= tardoc.CreateRichTextItem("Comments")