Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Open Outlook Programmatically

Posted on 2007-12-06
3
Medium Priority
?
1,181 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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 …
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

618 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