To anyone who can help!
Our company recently switched to Lotus Notes. I'm having problems in Access to use Notes to send out e-mails.
When I use the DoCmd.SendObject function it opens Lotus Notes if it's running and automatically creates a new e-mail with field automatically populated the way I want it. However, the problem is I can only use it once. When I click on the button to start the DoCmd.SendObject again, nothing happens. I would have to close the whole database and open it again to allow it to send another e-mail.
I did look at other threads for similar issues so I used the code below. This code does let me send out as many e-mails as I like, but the problem is I do not see the e-mail in Notes prior to it being send. It get send automatically. Is there a way to send in Access info to Lotus Notes e-mail first so a user can review the e-mail and then send it out and do this several times without having to close down Access?
Sub SendNotesMail(Subject As String, Attachment As String, Recipient As Variant, cc As String, BodyText As String, SaveIt As Boolean)
'Set up the objects required for Automation into lotus notes
Dim MailDb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself NotesDocument
Dim MailDoc2 As Object
Dim AttachME As Object 'The attachment richtextfile object
Dim session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
Dim CurrentDatabase As String
Dim NotesSS As Object
Dim NotesDb As Object
On Error GoTo Errshow:
Set NotesSS = CreateObject("Notes.NotesSession")
With NotesSS
Set NotesDb = .GETDATABASE("WAKEAM3/WYP", "mail\721116.nsf")
End With
With NotesDb
'Start a session to notes
Set session = CreateObject("Notes.NotesSession")
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
UserName = session.UserName
MailDbName = NotesDb.FileName
Set MailDb = session.GETDATABASE("", MailDbName)
If Not (MailDb.ISOPEN) = True Then MailDb.OPENMAIL
'Set up the new mail document
Set MailDoc = MailDb.CREATEDOCUMENT
With MailDoc
.Form = "Memo"
.sendto = Recipient
.CopyTo = cc
.Subject = Subject
.Body = BodyText
.SAVEMESSAGEONSEND = SaveIt
End With
'Set up the embedded object and attachment and attach it
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
End With
'Send the document
MailDoc.Send 0, Recipient
MsgBox "A copy of the Observation has been sent.", vbOKOnly, "Observation Sent"
Cleanup:
Set MailDb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set session = Nothing
Set EmbedObj = Nothing
Exit Sub
Errshow:
If Err.Number = 7063 Then
MsgBox "You have not logged onto Lotus Notes. Please log on and try to send again."
Else
MsgBox (Err.Description)
End If
GoTo Cleanup
End Sub
Our company recently switched to Lotus Notes. I'm having problems in Access to use Notes to send out e-mails.
When I use the DoCmd.SendObject function it opens Lotus Notes if it's running and automatically creates a new e-mail with field automatically populated the way I want it. However, the problem is I can only use it once. When I click on the button to start the DoCmd.SendObject again, nothing happens. I would have to close the whole database and open it again to allow it to send another e-mail.
I did look at other threads for similar issues so I used the code below. This code does let me send out as many e-mails as I like, but the problem is I do not see the e-mail in Notes prior to it being send. It get send automatically. Is there a way to send in Access info to Lotus Notes e-mail first so a user can review the e-mail and then send it out and do this several times without having to close down Access?
Sub SendNotesMail(Subject As String, Attachment As String, Recipient As Variant, cc As String, BodyText As String, SaveIt As Boolean)
'Set up the objects required for Automation into lotus notes
Dim MailDb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself NotesDocument
Dim MailDoc2 As Object
Dim AttachME As Object 'The attachment richtextfile object
Dim session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
Dim CurrentDatabase As String
Dim NotesSS As Object
Dim NotesDb As Object
On Error GoTo Errshow:
Set NotesSS = CreateObject("Notes.NotesSession")
With NotesSS
Set NotesDb = .GETDATABASE("WAKEAM3/WYP", "mail\721116.nsf")
End With
With NotesDb
'Start a session to notes
Set session = CreateObject("Notes.NotesSession")
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
UserName = session.UserName
MailDbName = NotesDb.FileName
Set MailDb = session.GETDATABASE("", MailDbName)
If Not (MailDb.ISOPEN) = True Then MailDb.OPENMAIL
'Set up the new mail document
Set MailDoc = MailDb.CREATEDOCUMENT
With MailDoc
.Form = "Memo"
.sendto = Recipient
.CopyTo = cc
.Subject = Subject
.Body = BodyText
.SAVEMESSAGEONSEND = SaveIt
End With
'Set up the embedded object and attachment and attach it
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
End With
'Send the document
MailDoc.Send 0, Recipient
MsgBox "A copy of the Observation has been sent.", vbOKOnly, "Observation Sent"
Cleanup:
Set MailDb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set session = Nothing
Set EmbedObj = Nothing
Exit Sub
Errshow:
If Err.Number = 7063 Then
MsgBox "You have not logged onto Lotus Notes. Please log on and try to send again."
Else
MsgBox (Err.Description)
End If
GoTo Cleanup
End Sub