Disable outlook popup (1 Viewer)

aziz rasul

Active member
Local time
Today, 17:15
Joined
Jun 26, 2000
Messages
1,935
At the company I work for I can't change the registry or download any third party software. In sending an email using outlook VBA code I want to add code that will disable or press the button on the outlook warning message. I don't it's possible but thought I would ask.
 

isladogs

MVP / VIP
Local time
Today, 17:15
Joined
Jan 14, 2017
Messages
18,258
Which Outlook warning message?

Anyway, I use the function below to send email from Access using Outlook
BUT Outlook doesn't need to be displayed to do so...

Save the code in a module.
If you try this you will probably need to define some variables as I normally do that at the start of each module

Code:
Public Function SendEmailUsingOutlook(strSendTo As String, strCopyTo As String, strSubject As String, strMessage As String, strAttachment As String)

On Error GoTo ErrHandler

'CR v5161 - Uses late binding to send email without displaying Outlook

Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim StartOutlookFlag As Boolean

StartOutlookFlag = False

' Create the Outlook session.
If IsAppRunning("Outlook.Application") = True Then
    'Use existing instance of Outlook
    Set objOutlook = CreateObject("Outlook.Application")
Else
   'Could not get instance of Outlook, so create a new one
        Path = GetAppExePath("outlook.exe")    'determine outlook's installation path
        Shell (Path), vbMinimizedFocus   'start outlook
        Do While Not IsAppRunning("Outlook.Application")
            DoEvents
        Loop
        Set objOutlook = GetObject(, "Outlook.Application") 'Bind to new instance of Outlook
        StartOutlookFlag = True 'needed so Outlook can be closed later
End If

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(0)

' Add the To/Subject/Body/Attachments to the message then send the message
With objOutlookMsg
    .To = strSendTo
    .CC = strCopyTo
    .Subject = strSubject
    .Body = strMessage
    If Nz(strAttachment, "") <> "" Then
        .Attachments.Add strAttachment
    End If
   ' .Display 'do not display message
    .Save
    .Send
End With

Set objOutlook = Nothing
Set objOutlookMsg = Nothing

'close Outlook if it was opened for this function - time may need modifiying
DoEvents
Wait 5 'allow time to send message
If StartOutlookFlag = True Then CloseOutlook

ErrHandlerExit:
   Exit Function

ErrHandler:
   If Err.Number <> 287 Then 'And err.Number <> 429 Then
        MsgBox "Error " & Err.Number & " in SendEMailUsingOutlook routine: " & Err.Description
   End If
   Resume ErrHandlerExit

End Function
Public Function SendEmailDisplayOutlook(strSendTo As String, strCopyTo As String, strSubject As String, strMessage As String, strAttachment As String)

On Error GoTo ErrHandler

'Uses late binding to send email(so that a reference to Outlook library is not needed)

Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim sAPPPath        As String

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(0)
' Add the To/Subject/Body/Attachments to the message then display the message for editing
With objOutlookMsg
    .To = strSendTo
    .CC = strCopyTo
    .Subject = strSubject
    .Body = strMessage
    If Nz(strAttachment, "") <> "" Then
        .Attachments.Add strAttachment
    End If
    .display
    '.Send
End With

Set objOutlook = Nothing
Set objOutlookMsg = Nothing

ErrHandlerExit:
   Exit Function

ErrHandler:
   MsgBox "Error " & Err.Number & " in SendEMailDisplayOutlook routine: " & Err.Description
   Resume ErrHandlerExit

End Function
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 09:15
Joined
Aug 30, 2003
Messages
36,134
If it's the "A program is trying to send..." warning, see:

https://www.rondebruin.nl/win/s1/security.htm

In particular the bit about the Outlook object model and the MSDN article. I've fixed by changing the programmatic option, and the virus bit.
 

isladogs

MVP / VIP
Local time
Today, 17:15
Joined
Jan 14, 2017
Messages
18,258
Thanks Paul

I haven't seen that message for many years but then I use Access 2010 & CDO for most purposes.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 09:15
Joined
Aug 30, 2003
Messages
36,134
CDO is good, I've used it a few times. I also send stuff out through SQL Server a lot. I sometimes use Outlook automation when it's for users and they want to see the emails in their Sent Items (rather than be copied). I like to have lots of tools in the toolbox; that way I can be confused more. :p
 

isladogs

MVP / VIP
Local time
Today, 17:15
Joined
Jan 14, 2017
Messages
18,258
Hi Paul

CDO is good, I've used it a few times. I also send stuff out through SQL Server a lot. I sometimes use Outlook automation when it's for users and they want to see the emails in their Sent Items (rather than be copied). I like to have lots of tools in the toolbox; that way I can be confused more.

I started using CDO many years ago when a network manager unilaterally decided to remove Outlook and replace it with Novell Groupwise. Unfortunately we couldn't get Access apps to send email using that so CDO was utilised instead.

Since then I've kept it as the main email process (as it works 'silently') but allow clients to choose Outlook as an alternative where preferred .

I've never thought about doing email direct from SQL server - is that easy or not?

Generally I find it easier to only make use of one or two methods - I get utterly overwhelmed (lost) if I've got too much choice ...

Have a good weekend
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 11:15
Joined
Feb 28, 2001
Messages
27,332
I used CDO a lot in the last couple of years before retirement. The biggest "gotcha" depends on how secure your internal network tries to be. We had to get our security folks to allow us exceptions for using a particular SMTP Gateway. Other than that, and the inability to send encrypted e-mails to an eventual Outlook receiver, CDO worked like a champ.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 09:15
Joined
Aug 30, 2003
Messages
36,134
I've never thought about doing email direct from SQL server - is that easy or not?

Like anything else there's a bit of a learning curve, but it's not hard. Lets you send email from stored procedures or triggers as well as VBA, and it allows for HTML or plain text.
 

Users who are viewing this thread

Top Bottom