Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is Outlook Open?

Status
Not open for further replies.

DaveL

Programmer
Jun 8, 2000
40
0
0
US
Using Access 2000 and Outlook 2000

I am trying to create a new task in Outlook from within Access. I have it working if Outlook is already open. Can anyone share with me the code that will check to see if Outlook is open, and if not, open Outlook in order to create the new task?

Thanks!
 
Hi DaveL,

This little app looks at the Title Bar to see if Outlook is on it, if not, opens Outlook. Paste this into a new Module, save the module as anything:

Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetActiveWindow Lib "user32.dll" () As Long
Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long

Global booIsThisOpen As Boolean
Global strIsThisopen As String

Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
On Error Resume Next
Dim slength As Long, TitleBar As String
Dim retval As Long
Static winnum As Integer
booIsThisOpen = False
winnum = winnum + 1
slength = GetWindowTextLength(hwnd) + 1
If slength > 1 Then
TitleBar = Space(slength)
retval = GetWindowText(hwnd, TitleBar, slength)
If InStr(TitleBar, strIsThisopen) Then
booIsThisOpen = True
Exit Function
End If
End If
EnumWindowsProc = 1
End Function

To test it, paste this into the Click event of a Button:

strIsThisopen = "Microsoft Outlook"
Call EnumWindows(AddressOf EnumWindowsProc, 0)
If booIsThisOpen = False Then
Call Shell("OutLook", 1)
End If

Obviously you don't need to use the Shell to Outlook, it's just there to see if it works for you.

Good luck

Bill
 
Bill,

Thank you so much for the help! The module you provided works great!

I have a quick follow-up questions on this topic... if Outlook is closed, is there any way to add a task from Access without opening Outlook first, or somehow making the process transparent to the user?

Thanks again!

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top