【问题标题】:Access VBA: Lotus Notes: select notes template & fill with data from AccessAccess VBA:Lotus Notes:选择注释模板并填充来自 Access 的数据
【发布时间】:2014-02-24 20:00:41
【问题描述】:

我遇到了一个奇怪的问题:我在 Access 中有一个 VBA 脚本,它在单击按钮时通过以下方式控制 Lotus Notes:

  • 连接并打开数据库
  • 搜索某个模板
  • 生成新邮件(在 uiview 中)
  • 将数据填充到正文和主题中
  • 将 Lotus Notes 放在前面

现在,如果用户再次单击我的 VBA 表单中的该按钮,则相同的过程会导致错误,因为

Set nMailDB = nSession.OpenDatabase(......) 

导致“无”!?!

有什么方法可以获取 Lotus Notes 中当前打开的任何 TAB 的标题/名称或任何内容?

Sub createNotesMail(frm As Form)
Dim nMailDb As Object
Dim nMailDoc As Object
Dim nMailTempDoc As Object
Dim nSession As Object
Dim nView As Object
Dim nWorkspace As Variant
Dim nCursor As Object
Dim nStationery As Object
Dim StationeryName As String

'Start Lotus Notes Session
Set nSession = CreateObject("Notes.NotesSession")
Set nMailDb = nSession.GetDatabase(NOTES_SERVER, NOTES_MAILIN)

' Open the Stationery View
Set nView = nMailDb.GetView("Stationery")
Set nWorkspace = CreateObject("Notes.NotesUIWorkspace")
Set nCursor = nView.GetFirstDocument

Do While Not nCursor Is Nothing
    ' get stationery value
    StationeryName = nCursor.GetItemValue("MailStationeryName")(0)
    ' match form template selection versus stationery
    If StationeryName = frm.TEMPLATE_NAME Then
        ' grab users signature from a temp UI document
        Set nMailTempDoc = nMailDb.CreateDocument
        Set nMailTempDoc = nWorkspace.Editdocument(True, nMailTempDoc)
        With nMailTempDoc
            .gotofield "Body"
            .SelectAll
            .Copy
            .Close
        End With

        ' create new document from stationery template, find and replace <PLACEHOLDERs>
        Set nMailDoc = nWorkspace.Editdocument(False, nCursor)
        With nMailDoc
            .gotofield "Body"
            .FINDSTRING "<SIGNATURE>"
            .Paste

            copyToClipboard frm.RECIPIENT
            .gotofield "Body"
            .FINDSTRING "<NAME>"
            .Paste

            copyToClipboard frm.DUEDATE
            .gotofield "Body"
            .FINDSTRING "<DUEDATE>"
            .Paste

            copyToClipboard frm.ORDERID
            .gotofield "Body"
            .FINDSTRING "<ORDERID>"
            .Paste

            Dim SubjectTemp As String
            SubjectTemp = .FIELDGETTEXT("Subject")
            SubjectTemp = Replace(SubjectTemp, "<ORDERID>", frm.ORDERID)
            SubjectTemp = Replace(SubjectTemp, "<DUEDATE>", frm.DUEDATE)
            .FIELDSETTEXT "Subject", SubjectTemp

            .FIELDSETTEXT "EnterSendTo", frm.RECIPIENT
        End With
        GoTo nMail_OK
    Else
        Set nCursor = nView.GetNextDocument(nCursor)
    End If
Loop

MsgBox "Error: Lotus Notes Template already opened or not found!"

nMail_OK:

Set nMailDb = Nothing
Set nMailDoc = Nothing
Set nMailTempDoc = Nothing
Set nSession = Nothing
Set nView = Nothing
Set nWorkspace = Nothing
Set nCursor = Nothing
Set nStationery = Nothing
End Sub

【问题讨论】:

  • 据我所知,这是由 Notes 管理的。您是否在按钮末尾关闭笔记会话?也许有些物品被回收了?更多代码更多帮助:-)

标签: database ms-access uiview vba lotus-notes


【解决方案1】:

正如Thommy Tomka 之前在an edit to the question 中回答的那样


我找到了一个可能的原因:如果我选择打开并填充数据库中数据的模板已经在 Lotus Notes 中打开,那么“MailStationeryName”为空!一旦模板关闭,值就会恢复到应有的值:

StationeryName = nCursor.GetItemValue("MailStationeryName")(0)

现在这对我有用!我将扩展脚本来检查我的数据库使用的任何 Lotus Notes 模板是否已打开,这意味着用户尚未完成任务。

NOTES_SERVER and NOTES_MAILIN are CONSTs declared elsewhere.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-12
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多