Avoid Security Prompts

S

SHIPP

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top