Solved

Open Outlook Programmatically

Posted on 2007-12-06
3
1,161 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 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Slow running query - help 16 36
MS Access Error Handling 6 29
Trying to export a table to another Access database file 2 16
run FileCopy code from a string 6 14
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 …
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

749 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