'--------------------------------------------------------------------------------------
'Query exporteren naar XLS bestand, en mailen als bijlage.
'--------------------------------------------------------------------------------------
Private Sub cmdExport_Click()
On Error GoTo Err_cmdExport_Click
Dim stDocName As String, StartDatum As Date
Dim sFile As String
StartDatum = Date
sFile = "J:\_HelpMij_Archief\2011\Access\DeclaratieCTG - " & StartDatum & ".xls"
DoCmd.OutputTo acOutputQuery, "DeclaratieCTG", acFormatXLS, sFile
'----------------------------------------------------------------------------------
'Variant met Late Binding (geen Outlook referentie nodig)
'----------------------------------------------------------------------------------
Dim olApp As Object
Dim olMail As Object
Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(0)
'----------------------------------------------------------------------------------
'Variant met Early Binding (Werkt niet zonder Outlook referentie)
'----------------------------------------------------------------------------------
''Dim olApp As Outlook.Application
''Dim olMail As Outlook.MailItem
''Set olApp = New Outlook.Application
''Set olMail = olApp.CreateItem(olMailItem)
'----------------------------------------------------------------------------------
With olMail
.To = "naam@provider.nl"
.CC = "naam@andereprovider.nl"
.Subject = "Hier is het dagelijkse bestandje."
.Body = "Met vriendelijke groet, en vul de rest maar zelf in..."
.Attachments.Add sFile
.Display
'.Send
End With
Set olMail = Nothing
Set olApp = Nothing
Exit Sub
Err_cmdExport_Click:
MsgBox Err.Description
End Sub