Solved

Open Outlook Programmatically

Posted on 2007-12-06
3
1,149 Views
Last Modified: 2012-05-05
I am using docmd.sendobject to send a .snp.  It works fine.  I have moved it to another computer and it doesn't work unless Outlook is open.  What is the code to open Outlook?   Thanks for your help.
0
Comment
Question by:Sasha42
3 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 250 total points
ID: 20421333
Try:
Dim olApp As Object
Set olApp = CreateObject("Outlook.Application")
DoEvents
'put your sendobject here
DoEvents
Set olApp = Nothing

Open in new window

0
 

Author Comment

by:Sasha42
ID: 20421696
Thanks matthewpatrick.  It did not work.  Is Outlook supposed to open?  It didn't open.
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 250 total points
ID: 20421790

Add to your references  Microsoft Outlook xx.x object library

first check if outlook is open

private sub cmdButton_click()
If IsOutlookOpen = False Then
    MsgBox "Cannot open Outlook"
    Exit Sub
End If
'rest of your codes here


end sub


**Place this codes in a module or in form's module

Function IsOutlookOpen() As Boolean
' The IsOutlookOpen() function sets the Outlook Application
' and Namespase objects and opens MS Outlook if close
On Error Resume Next
Dim objOut As New Outlook.Application
Dim objNS As NameSpace, fIsOpen As Boolean


' Assume Outlook is open
fIsOpen = True

Set objOut = GetObject("", "Outlook.application")

' If Outlook is NOT Open, then there will be an error.
' Attempt to open Outlook
If Err.Number > 0 Then
    Err.Clear
    Set objOut = CreateObject("Outlook.application")
       
    If Err.Number > 0 Then
        MsgBox "Could not create Outlook object", vbCritical
        fIsOpen = False
        Exit Function
    End If
End If

' If we've made it this far, we have an Outlook App Object
' Now, set the NameSpace object to MAPI Namespace
Set objNS = objOut.GetNamespace("MAPI")
   
If Err.Number > 0 Then
    MsgBox "Could not create NameSpace object", vbCritical
    fIsOpen = False
    Exit Function
End If

' Return the Success Flag as the value of IsOutlookOpen()
IsOutlookOpen = fIsOpen
   
End Function


0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
unable to save new report from old one 9 29
Normalization of a table 19 73
Create tables in access db (2016)  using vba 13 41
Dlookup MSACCESS 5 25
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question