Remember to add the OUTLOOK OBJECTS in the vbe menu
Code:
Public Sub SendEmail()
Dim sBody as string
Dim vTo vSubj
vSubj = "Teste" & " " & rst![SAP] & " " & rst![Nome]
sBody = "your body here"
Send1Email vTo, vSubj, sBody
End Sub
'----------------
'YOU MUST ADD THE OUTLOOK APP IN REFERENCES!!! checkmark OUTLOOK OBJECTS in the vbE menu, Tools, References
'-------------
Public Function Send1Email (ByVal pvTo, ByVal pvSubj, ByVal pvBody, optional pvFile ) As Boolean
Dim oApp As Outlook.Application
Dim oMail As Outlook.MailItem
On Error GoTo ErrMail
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(olMailItem)
With oMail
.To = pvTo
.Subject = pvSubj
.Body = pvBody
if not isMissing(pvFile) then .Attachments.Add pvFile, olByValue, 1
.Send
End With
EmailO = True
Set oMail = Nothing
Set oApp = Nothing
Exit Function
ErrMail:
MsgBox Err.Description, vbCritical, Err
Resume Next
End Function