I have tested the proposed solution and unfortunately I'm doing something wrong.
While trying to create the new email object, with the line "Set olMailItem = olApp.CreateItem(olMailItem)", I'm receiveing the following error message:
Error 91
The object variable or the variable of the 'with' block was not defined.
I could not handle the error.
The procedures I have used are subscribed, but any way, with your help I think I could jump to the next step with the instruction DoCmd.SendObject.
If you can continue help me with the issue I'm facing would be very glad, but any way, I think I can handle from here.
Thank you very very much.
- Public Function SendEmailWithOutlook(MessageTo As String, Subject As String, MessageBody As String)
-
-
' Define app variable and get Outlook using the "New" keyword
-
Dim olApp As New Outlook.Application
-
Dim olMailItem As Outlook.MailItem ' An Outlook Mail item
-
-
' Create a new email object
-
Set olMailItem = olApp.CreateItem(olMailItem)
-
-
Debug.Print MessageTo, Subject, MessageBody
-
-
' Add the To/Subject/Body to the message and display the message
-
With olMailItem
-
.To = MessageTo
-
.Subject = Subject
-
.Body = MessageBody
-
.Send ' Send the message immediately
-
End With
-
-
' Release all object variables
-
Set olMailItem = Nothing
-
Set olApp = Nothing
-
-
End Function
-
Private Sub Comando161_Click()
-
Dim Vx As Variant
-
-
On Error GoTo Err_Comando161_Click
-
-
Vx = SendEmailWithOutlook("Ricardo.Milano@GrupoAutcomp.com.br", "Impossível cotar", "Test")
-
-
'DoCmd.SendObject acSendNoObject, , , "Ricardo.Milano@GrupoAutcomp.com.br", , , "Impossível cotar", "Just a test"
-
-
Exit_Comando161_Click:
-
Exit Sub
-
-
Err_Comando161_Click:
-
Call ErrMsg("Private Sub Comando161_Click()", Me.Name)
-
Resume Exit_Comando161_Click
-
-
End Sub