?
Solved

Opening Outlook from Access, if not already open

Posted on 2009-02-13
10
Medium Priority
?
818 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

0
Comment
Question by:Greekiwi
  • 5
  • 4
10 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 23639361


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
0
 

Author Comment

by:Greekiwi
ID: 23639379
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
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 2000 total points
ID: 23639501
   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
0
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.

 

Author Comment

by:Greekiwi
ID: 23639819
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."
0
 
LVL 85
ID: 23640538
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
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 23640681
i tested those codes i posted and it works without any problem.
0
 

Author Comment

by:Greekiwi
ID: 23642613
Are you running Vista / Office 07? As I still get the error I posted earlier.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 23642675
XP/A2003
0
 

Author Comment

by:Greekiwi
ID: 23642757
That could be the problem. Have you ever encountered that problem before with any other things?
0
 

Accepted Solution

by:
Greekiwi earned 0 total points
ID: 23644362
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

0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

839 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