使用 FieldAppendText 向字段添加文本

Adding text to field with FieldAppendText

我正在尝试在单击按钮时使用 .FieldAppendText 将文本添加到文本字段。

按钮点击事件中的代码:

Sub Click(Source As Button)
    Dim workspace As New NotesUIWorkspace
    Dim uidoc As NotesUIDocument
    Set uidoc = workspace.CurrentDocument
    Call uidoc.FieldAppendText _
    ( "testejam", "kappa" )
End Sub

单击按钮时,文本会添加到字段中,但问题是添加的文本不会出现在新行中,但我已经设置了文本字段属性 "Separate values when user enters"- "New line" 和 "Display separate values with"- "New line"。我看不出问题出在哪里,也看不出每次按下按钮时文本都没有添加到新行的原因。

自己添加新行 Chr(10):

Call uidoc.FieldAppendText("testejam", Chr(10) + "kappa")

您提到的其他选项只有在您将新的列表元素添加到字段时才有效。

如果您真的只想在没有多个值的情况下向文本字段添加新行,那么 Kurt 的解决方案是正确的(尽管我会在 windows 电脑上使用 Chr$(13) + Chr$(10)与手动按回车键相同)。

但是,如果您希望在您的字段中包含 "multiple values",那么 Knuts 答案仅适用于您的字段将 "New Line" 作为分隔符集的情况。

如果您更改它或想更多地使用此代码 "universally",请使用 NotesItem Class 的后端文档和 AppendToTextList- 方法来执行此更改:

Sub Click(Source As Button)
    Dim workspace As New NotesUIWorkspace
    Dim uidoc As NotesUIDocument
    Dim doc as NotesDocument
    Dim item as NotesItem
    Set uidoc = workspace.CurrentDocument
    Set doc = uidoc.Document
    Set item = doc.GetFirstitem( "testejam" )
    Call item.AppendToTextList( "kappa" )
End Sub

您可能需要 Call Source.Refresh 作为最后一行以使更改可见。

此方法与字段中使用的字段分隔符无关 "testejam"。

此外,如果 "testejam" 是计算字段,此代码也有效。 uidoc 解决方案对于计算字段将失败。