Solved

Open Outlook Programmatically

Posted on 2007-12-06
3
1,122 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
Comment Utility
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
Comment Utility
Thanks matthewpatrick.  It did not work.  Is Outlook supposed to open?  It didn't open.
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 250 total points
Comment Utility

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now