Outlook running? (1 Viewer)

geralf

Registered User.
Local time
Today, 02:32
Joined
Nov 15, 2002
Messages
212
Hi,

I'm sending an e-mail each time a spesific report is made. If the user has'nt opened Outlook, it is placed in Outlook's Outbox, and is sent first when the user opens Outlook. Can I somehow start Outlook using VBA so the email gets sent when the report is run?

Also, The user is prompted with a warning message that an application tries to send an email. The user has to allow this for the mail to be sent. I know this is a security matter so no applicatopn can send emails without the user knowing. Is there someway to do this without the warning?

I'm using WXP and A2K3

Thanks in advance.
 

Moniker

VBA Pro
Local time
Yesterday, 20:32
Joined
Dec 21, 2006
Messages
1,567
Use the Outlook object to create an instance of Outlook running (won't make a second instance if it's already running), and set the security to low to avoid the warning.

Access.AutomationSecurity msoAutomationSecurityLow

You can also use the DoCmd.SendObject to do this, but you don't have as much control over Outlook this way.
 

geralf

Registered User.
Local time
Today, 02:32
Joined
Nov 15, 2002
Messages
212
Thanks for your reply.

I'm having some troubles using the code. I have just tried putting the code in my email sub, but I still get the warning message. (The one where you can allow access for a period of time). I tried disabling it as well without any luck. Whet am I doing wrong?

Sub SendMail(strSubject As String, strBody As String, Optional AttachmentPath, _
Optional Recipient As String)


Access.AutomationSecurity = msoAutomationSecurityForceDisable

Dim bStarted As Boolean
Dim objOutlook As Outlook.Application
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookAttach As Outlook.Attachment

On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set objOutlook = CreateObject("Outlook.Application")
bStarted = True
End If

Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
.Subject = strSubject
.Body = strBody
If Not IsMissing(Recipient) Then
Set objOutlookRecip = .Recipients.Add(Recipient)
objOutlookRecip.TYPE = olTo
.Recipients = Recipient
End If
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
.Display
'.Save
If bStarted Then
Set objOutlookRecip = Nothing
Set objOutlook = Nothing
Set objOutlookMsg = Nothing
End If
End With
End Sub



Thanks for your help.
 

Moniker

VBA Pro
Local time
Yesterday, 20:32
Joined
Dec 21, 2006
Messages
1,567
Have you tried using the .Send instead of the .Save?
 

geralf

Registered User.
Local time
Today, 02:32
Joined
Nov 15, 2002
Messages
212
Thanks for the help. Most appreciated,
 

Users who are viewing this thread

Top Bottom