'This is the procedure that calls the Outlook VBA function...
Public Function SendEmail(strTo As String, _
strSubject As String, _
strMessageBody As String, _
Optional strAttachmentPaths As String, _
Optional strCC As String, _
Optional strBCC As String) As Boolean
Dim objOutlook As Object
Dim objNameSpace As Object
Dim objExplorer As Object
Dim blnSuccessful As Boolean
Dim blnNewInstance As Boolean
'Is an instance of Outlook already open that we can bind to?
On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
On Error GoTo 0
If objOutlook Is Nothing Then
'Outlook isn't already running - create a new instance...
Set objOutlook = CreateObject("Outlook.Application")
blnNewInstance = True
'We need to instantiate the Visual Basic environment... (messy)
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set objExplorer = objOutlook.Explorers.Add(objNameSpace.Folders(1), 0)
objExplorer.CommandBars.FindControl(, 1695).Execute
objExplorer.Close
Set objNameSpace = Nothing
Set objExplorer = Nothing
End If
blnSuccessful = objOutlook.FnSendMailSafe(strTo, strCC, strBCC, _
strSubject, strMessageBody, _
strAttachmentPaths)
If blnNewInstance = True Then objOutlook.Quit
Set objOutlook = Nothing
SendEmail = blnSuccessful
End Function
Public Function ExportEmailFile(strOutputFile As String, _
strObjectName As String, _
strOutputType As String)
Dim strFileType As String
If Len(Dir(strOutputFile)) Then
Kill strOutputFile
End If
If strOutputType = "Report" Then
DoCmd.OutputTo acOutputReport, strObjectName, acFormatRTF, strOutputFile, False
ElseIf strOutputType = "Query" Then
DoCmd.OutputTo acOutputQuery, strObjectName, acFormatXLS, strOutputFile, False
End If
End Function