this code is everywhere on the forum. Dont know how you missed it.
Code:
sFile = folder & [Forms]![FormMilitairen]![national_number] & " - Verschilstaat Nr " & [Forms]![FormMilitairen]![SubFormVerschilstaat].[Form]![VerschilstaatID] & ".pdf"
DoCmd.OutputTo acOutputReport, strDocName, acFormatPDF, sFile
sTo = "bob@acme.com"
sSubj = "your data"
sBody = "dear bob, here's your data"
call Email1(sTo, sSubj, sBody, sFile)
put this code into a module for all to use.
Code:
Public Function Email1(ByVal pvTo, ByVal pvSubj, ByVal pvBody, Optional ByVal pvFile) As Boolean
Dim oApp As Outlook.Application
Dim oMail As Outlook.MailItem
On Error GoTo ErrMail
'NOTE : YOU MUST HAVE THE OUTLOOK REFERENCE CHECKED IN VBE; ctl-G, menu,tools, references, Microsoft Outlook XX Object library
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.createitem(olMailItem)
With oMail
.To = pvTo
.Subject = pvSubj
If Not IsNull(pvBody) Then .Body = pvBody
If Not IsMissing(pvFile) Then .Attachments.Add pvFile, olByValue, 1
.Display True
'.Save 'draft, we are NOT sending...we save as draft
.Send
End With
Email1 = True
endit:
Set oMail = Nothing
Set oApp = Nothing
Exit Function
ErrMail:
MsgBox Err.Description, vbCritical, Err
Resume endit
End Function