Emailing via Outlook

Gkirkup

Registered User.
Local time
Today, 13:31
Joined
Mar 6, 2007
Messages
628
I have an email form (I am trying this out with the sample form conveniently provided with a well known Acesss book), but when attempting to send an email it cannot find 'outlook.application'. I do have Outlook running. Is there anything special that I need to do to let Access find Outlook?
In the dim & distant past I remember similar error messages with Excel, but can't remember how that was fixed.

Robert
 
dim the object. make sure the DLL is included in access's abilities to access
 
Thanks. I see that you have to use VBA to add the Outlook object library.
 
Does anyone know how to avoid the annoying warning messages when sending email via Outlook?

Robert
 
Does anyone know how to avoid the annoying warning messages when sending email via Outlook?

Robert

"A PROGRAM IS TRYING TO ACCESS SEND MAIL ON YOUR BEHALF?"

yes. there is a solution, and I can't remember it, but if you google that message phrase specifically, you'll pull over a billion threads dealing with the issue. I think it's a setting, and yes it can be supressed.
 
Try this one. I found it somewhere some years ago. Hope it helps

Setting up the Outlook VBA code
Open Outlook
Go to the menu item Tools / Macro / Visual Basic Editor
In the VB environment expand the project node (usually called 'Project1')
Find and open the module 'ThisOutlookSession' (double click to open)
Copy and paste the code from below



Option Explicit
' Code: Send E-mail without Security Warnings
Private Sub Application_Startup()
'this is simply forces VBA to open
End Sub
' FnSendMailSafe
' --------------
' Calling this function by Automation will prevent the warnings
' 'A program is trying to send a mesage on your behalf...'
' Also features optional HTML message body and attachments by file path.
' The To/CC/BCC/Attachments function parameters can contain multiple items by seperating
' them by a semicolon. (e.g. for the strTo parameter, 'test@test.com; test2@test.com' is
' acceptable for sending to multiple recipients.
'
Public Function FnSendMailSafe(strTo As String, _
strCC As String, _
strBCC As String, _
strSubject As String, _
strMessageBody As String, _
Optional strAttachments As String) As Boolean
On Error GoTo ErrorHandler:
Dim MAPISession As Outlook.NameSpace
Dim MAPIFolder As Outlook.MAPIFolder
Dim MAPIMailItem As Outlook.MailItem
Dim oRecipient As Outlook.Recipient

Dim TempArray() As String, varArrayItem As Variant, strEmailAddress As String, strAttachmentPath As String, blnSuccessful As Boolean
'Get the MAPI NameSpace object
Set MAPISession = Application.Session
If Not MAPISession Is Nothing Then
'Logon to the MAPI session
MAPISession.Logon , , True, False
'Create a pointer to the Outbox folder
Set MAPIFolder = MAPISession.GetDefaultFolder(olFolderOutbox)
If Not MAPIFolder Is Nothing Then
'Create a new mail item in the "Outbox" folder
Set MAPIMailItem = MAPIFolder.Items.Add(olMailItem)
If Not MAPIMailItem Is Nothing Then
With MAPIMailItem
'Create the recipients TO
TempArray = Split(strTo, ";")
For Each varArrayItem In TempArray
strEmailAddress = Trim(varArrayItem)
If Len(strEmailAddress) > 0 Then
Set oRecipient = .Recipients.Add(strEmailAddress)
oRecipient.Type = olTo
Set oRecipient = Nothing
End If
Next varArrayItem
'Create the recipients CC
TempArray = Split(strCC, ";")
For Each varArrayItem In TempArray
strEmailAddress = Trim(varArrayItem)
If Len(strEmailAddress) > 0 Then
Set oRecipient = .Recipients.Add(strEmailAddress)
oRecipient.Type = olCC
Set oRecipient = Nothing
End If
Next varArrayItem
'Create the recipients BCC
TempArray = Split(strBCC, ";")
For Each varArrayItem In TempArray
strEmailAddress = Trim(varArrayItem)
If Len(strEmailAddress) > 0 Then
Set oRecipient = .Recipients.Add(strEmailAddress)
oRecipient.Type = olBCC
Set oRecipient = Nothing
End If
Next varArrayItem
'Set the message SUBJECT
.Subject = strSubject
'Set the message BODY (HTML or plain text)
If StrComp(Left(strMessageBody, 6), "<HTML>", vbTextCompare) = 0 Then
.HTMLBody = strMessageBody
Else
.Body = strMessageBody
End If
'Add any specified attachments
TempArray = Split(strAttachments, ";")
For Each varArrayItem In TempArray
strAttachmentPath = Trim(varArrayItem)
If Len(strAttachmentPath) > 0 Then
.Attachments.Add strAttachmentPath
End If
Next varArrayItem
.Send 'No return value since the message will remain in the outbox if it fails to send
Set MAPIMailItem = Nothing
End With
End If
Set MAPIFolder = Nothing
End If
MAPISession.Logoff
End If
'If we got to here, then we shall assume everything went ok.
blnSuccessful = True

ExitRoutine:
Set MAPISession = Nothing
FnSendMailSafe = blnSuccessful

Exit Function

ErrorHandler:
MsgBox "An error has occured in the user defined Outlook VBA function FnSendMailSafe()" & vbCrLf & vbCrLf & _
"Error Number: " & CStr(Err.Number) & vbCrLf & _
"Error Description: " & Err.Description, vbApplicationModal + vbCritical
Resume ExitRoutine
End Function
 

Users who are viewing this thread

Back
Top Bottom