Open Ms Outlook using Relative Path

B

bobdydd

Hi Everybody

Access 2000, Outlook 2000 Windows XP

I am running the code below to open Microsoft Outlook from a Command
Button. It works fine until I tried it on a machine that has Office
installed on something other than the "C" drive.

So can anyone advise me how to open Outlook by using a relative path
rather than the code I am using here.

Thanks
Bob

Private Sub CmdOpen_Click()
On Error GoTo Err_Error_Click
Dim MyAppID, ReturnValue
Dim MyXL As Object
Set MyXL = GetObject(, "Outlook.Application")
MsgBox "OUTLOOK IS ALREADY RUNNING", vbInformation, "Oops!"
Exit_Error_Click:
Exit Sub
Err_Error_Click:
If Err.Number = 429 Then
MyAppID = Shell("C:\Program Files\Microsoft
Office\Office\OUTLOOK.EXE", 1)
Else
MsgBox Err.Description
End If
Resume Exit_Error_Click
End Sub
 
D

Douglas J Steele

Not sure I see how being able to use a relative path will help. Relative to
what? Just because you know where Access has been installed doesn't
guarantee that Outlook has been installed to the same location.

I believe you can use the code in http://www.mvps.org/access/api/api0023.htm
at "The Access Web" to find the complete path. Of course, you'd need to know
where the pst files are stored...
 
B

bobdydd

Hi Doug

I was probably barking up the wrong tree with relative paths
My work buddy sent me this code which does the trick, although I would
like to try it on a PC that has MS Office installed on somewhere other
than the "C" drive.

Anyways thanks for the reply and here is the code I'm using. You may be
able to tidy it up.

Private Sub CmdOpen_Click()
On Error GoTo Err_Error_Click
Dim MyAppID, ReturnValue
Dim MyXL As Object
Set MyXL = GetObject(, "Outlook.Application")
MsgBox "OUTLOOK IS ALREADY RUNNING", vbInformation, "Oops!"
Exit_Error_Click:
Exit Sub
Err_Error_Click:
If Err.Number = 429 Then
Dim oShell As Object
Set oShell = CreateObject("WScript.Shell")
oShell.Run "Outlook"
DoCmd.Close
Else
MsgBox Err.Description
End If
Resume Exit_Error_Click
End Sub
 
D

Douglas J. Steele

What's the intent? Simply to open Outlook, but not to do anything with it?

Try:

Dim objOutlook As Object

Private Sub CmdOpen_Click()
On Error GoTo Err_Error_Click

Set outOutlook = GetObject(, "Outlook.Application")
MsgBox "OUTLOOK IS ALREADY RUNNING", vbInformation, "Oops!"

Exit_Error_Click:
Exit Sub

Err_Error_Click:
If Err.Number = 429 Then
Set objOutlook = CreateObject("Outlook.Application")
Else
MsgBox Err.Description
End If
Resume Exit_Error_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top