?
Solved

Open Outlook Programmatically

Posted on 2007-12-06
3
Medium Priority
?
1,174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 1000 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

752 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