vFile = "C:\mypath\files\ExportFile.xlsx"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12xls, "qsMyQuery", vFile, True
Send1Email "wileE@acme.com", "your file", "look at this file", vFile
Code:
'-------
'YOU MUST ADD THE OUTLOOK APP IN REFERENCES!!! checkmark MICROSOFT OUTLOOK OBJECT LIBRARY in the vbE menu, Tools, References
'-------
Public Function Email1(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 = GetApplication("Outlook.Application")
'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
' .Display True
End With
Email1 = True
Set oMail = Nothing
Set oApp = Nothing
Exit Function
Function GetApplication(className As String) As Object
' function to encapsulate the instantiation of an application object
Dim theApp As Object
On Error Resume Next
Set theApp = GetObject(, className)
If Err.Number <> 0 Then
MsgBox "Unable to Get" & className & ", attempting to CreateObject"
Set theApp = CreateObject(className)
End If
If theApp Is Nothing Then
Err.Raise Err.Number, Err.Source, "Unable to Get or Create the " & className & "!"
Set GetApplication = Nothing
End If
'MsgBox "Successfully got a handle on Outlook Application, returning to caller"
Set GetApplication = theApp
End Function