访问VBA:Lotus Notes:选择备注模板&填充来自Access的数据

时间:2014-02-24 20:00:42

标签: database uiview access-vba lotus-notes

我遇到一个奇怪的问题:我在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

1 个答案:

答案 0 :(得分:0)

正如Thommy Tomka an edit to the question之前的回答:

我找到了一个可能的原因:如果模板,我选择打开并填充我的数据库中的数据已经在Lotus Notes中打开,那么&#34; MailStationeryName&#34;是空的!模板关闭后,值将返回到应该是:

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

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

NOTES_SERVER and NOTES_MAILIN are CONSTs declared elsewhere.