View Single Post
  #1  
Old January 31st 08, 06:36 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Avoid Security Prompts

Replacing objOutlookApp with Application would work if you were working from
Outlook VBA.
In case of Access, CreateObject("Outlook.Application") is the only option.
See http://outlookcode.com/article.aspx?id=52

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"SHIPP" wrote in message
...
I am using Access 2003 to automate an email. The following is my code.


Function sendMessage(strTo As String, strSubject As String, _
strComments As String, Optional AttachmentPath)

Dim objOutlookApp As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecipient As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

' Create the Outlook session.
Set objOutlookApp = CreateObject("Outlook.Application")
' Set objOutlookApp = Application
' Create the message.
Set objOutlookMsg = objOutlookApp.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecipient = .Recipients.Add(strTo)
objOutlookRecipient.Type = olTo

' Set the Subject, Body, and Importance of the message.
.Subject = strSubject
.Body = strComments & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If

' Resolve each Recipient's name
For Each objOutlookRecipient In .Recipients
objOutlookRecipient.Resolve
If Not objOutlookRecipient.Resolve Then
objOutlookMsg.Display ' Display any names that can't be resolved
End If
Next
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlookApp = Nothing

End Function

The email is sent but it prompts 6 times because of security. In a
previous
comment to another user Sue Mosher indicated that the following line

Set objOutlookApp = CreateObject("Outlook.Application")

Should be changed to:

Set objOutlookApp = Application

I have tried this and now I get a Type Mismatch error. Any ideas on how to
eliminate the security questions would be appreciated.

--
M. Shipp



Ads