We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Opening Outlook from Access, if not already open

Greekiwi
Greekiwi asked
on
Medium Priority
843 Views
Last Modified: 2012-05-06
I have a code that opens MS Outlook from Access. However if I click it, and Outlook is already open, it opens another copy of it.

What I want is, if Outlook is already open, it just brings it to focus, not opens another copy.
MyAppID = Shell("C:\Program Files (x86)\Microsoft Office\Office12\Outlook.exe", 1)

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:


Dim oOutlook As Object
    Dim oNameSpace As Object
    Dim oInbox As Object
     
    Set oOutlook = CreateObject("Outlook.Application")
    Set oNameSpace = oOutlook.GetNamespace("MAPI")
    Set oInbox = oNameSpace.Folders(1)
     
    oOutlook.Quit 'Close All Outlook copies if open

    Set oInbox = oInbox.Folders("Inbox")
    oInbox.Display

Author

Commented:
Hi Capricorn,

This closes all other windows of Outlook, but doesn't open a new one. When I click it a second time it opens (not fully maximised) with Inbox open.

I have Outlook set to open with calendar, so if I could retain that, it would be nice.

Cheers
CERTIFIED EXPERT
Top Expert 2016
Commented:
   Dim oOutlook As Object
    Dim oNameSpace As Object
    Dim oInbox As Object
    Dim oFld As Outlook.MAPIFolder
 
    Set oOutlook = CreateObject("Outlook.Application")
    Set oNameSpace = oOutlook.GetNamespace("MAPI")
    Set oInbox = oNameSpace.Folders(1)
    Set oFld = oNameSpace.GetDefaultFolder(olFolderCalendar)

    oOutlook.Quit 'Close All Outlook copies if open

 '   Set oInbox = oInbox.Folders("Inbox")
 '   oInbox.Display
    oFld.Display
    oOutlook.ActiveExplorer.WindowState = 0

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
It opens one when nothing is open, but when one is open I get this message:

"Cannot set the WindowState of this Explorer or Inspector since it has not yet been made visible."
Scott McDaniel (EE MVE )Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
You might read over this. It includes code samples that show how to check to see if your CreateObject call suceeds or fails:

http://msdn.microsoft.com/en-us/library/aa164798(office.10).aspx
CERTIFIED EXPERT
Top Expert 2016

Commented:
i tested those codes i posted and it works without any problem.

Author

Commented:
Are you running Vista / Office 07? As I still get the error I posted earlier.
CERTIFIED EXPERT
Top Expert 2016

Commented:
XP/A2003

Author

Commented:
That could be the problem. Have you ever encountered that problem before with any other things?
Commented:
I have modified your code to find one that works for me.
Private Sub Command38_Click()
Dim oOutlook As Object
    Dim oNameSpace As Object
    Dim oInbox As Object
    Dim oFld As Outlook.MAPIFolder
     
    Set oOutlook = CreateObject("Outlook.Application")
    Set oNameSpace = oOutlook.GetNamespace("MAPI")
    Set oFld = oNameSpace.GetDefaultFolder(olFolderCalendar)
     
    oOutlook.Quit 'Close All Outlook copies if open
    
    MyAppID = Shell("C:\Program Files (x86)\Microsoft Office\Office12\Outlook.exe", 1)
    oOutlook.ActiveExplorer.WindowState = 0
 
End Sub

Open in new window

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.