【发布时间】: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