Article ID: 124393
Article Last Modified on 11/6/2000
OnTimer: [Event Procedure]
TimerInterval: 500
Option Explicit
Declare Function GetActiveWindow Lib "User" () As Integer
Declare Function GetParent Lib "User" (ByVal hWnd As Integer) _
As Integer
Declare Function GetFocus Lib "User" () As Integer
Sub Form_Timer ()
Dim RetVal As Integer
Dim CurrhWnd As Integer
Dim AccesshWnd As Integer
Static ActiveApphWnd As Integer
' Get the Microsoft Access window handle (hWnd).
AccesshWnd = GetAccesshWnd()
' Get the active application window handle (hWnd).
CurrhWnd = GetActiveApphWnd()
' The first time through, just record the current
' window handle.
If ActiveApphWnd = 0 Then
ActiveApphWnd = CurrhWnd
Exit Sub
End If
' Determine if the current window handle differs from the
' previous window handle (focus change).
If CurrhWnd <> ActiveApphWnd Then
' Record the current window handle.
ActiveApphWnd = CurrhWnd
' Determine if the current handle is the Microsoft Access
' handle (activate Microsoft Access?).
If ActiveApphWnd = AccesshWnd Then
Access_Activate
Else
Access_Deactivate
End If
End If
End Sub
Sub Access_Activate ()
' Insert the code that you want to run when Microsoft Access
' is activated here.
End Sub
Sub Access_Deactivate ()
' Insert the code that you want to run when Microsoft Access
' is deactivated here.
End Sub
Function GetAccesshWnd ()
GetAccesshWnd = GetTopMosthWnd(Me.hWnd)
End Function
Function GetActiveApphWnd ()
GetActiveApphWnd = GetTopMosthWnd(GetActiveWindow())
End Function
Function GetTopMosthWnd (ByVal hWnd)
Dim hWndTopMost As Integer
hWndTopMost = hWnd
' Find the top window without a parent window.
While hWnd <> 0
hWndTopMost = hWnd
hWnd = GetParent(hWnd)
Wend
GetTopMosthWnd = hWndTopMost
End Function
Sub Access_Activate ()
MsgBox "Microsoft Access was activated"
End Sub
Keywords: kbhowto kbprogramming KB124393