Drew Wutka
DWUTKA at marlow.com
Thu Oct 9 12:54:03 CDT 2003
Put a command button on your form called cmdAlwaysOnTop, then paste the following code behind your form... Option Compare Database Option Explicit Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _ ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal _ cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _ ByVal nCmdShow As Long) As Long Const SW_HIDE = 0 Private Const SW_SHOW = 5 Private Const SWP_NOMOVE = &H2 Private Const SWP_NOSIZE = &H1 Private Const HWND_TOPMOST = -1 Private Const HWND_NOTOPMOST = -2 Private Sub cmdAlwaysOnTop_Click() If IsWindowVisible(Application.hWndAccessApp) Then ShowWindow Application.hWndAccessApp, SW_HIDE SetWindowPos Application.hWndAccessApp, HWND_TOPMOST, 0, 0, 0, 0, _ SWP_NOMOVE Or SWP_NOSIZE ShowWindow Me.hwnd, SW_SHOW 'Not needed in Access 97 Me.Repaint 'Not needed in Access 97 Else ShowWindow Application.hWndAccessApp, SW_SHOW SetWindowPos Application.hWndAccessApp, HWND_NOTOPMOST, 0, 0, 0, 0, _ SWP_NOMOVE Or SWP_NOSIZE End If End Sub Private Sub Form_Unload(Cancel As Integer) If IsWindowVisible(Application.hWndAccessApp) = False Then ShowWindow Application.hWndAccessApp, SW_SHOW SetWindowPos Application.hWndAccessApp, HWND_NOTOPMOST, 0, 0, 0, 0, _ SWP_NOMOVE Or SWP_NOSIZE End If End Sub This code works in 97 and 2000, and Susan is testing it in XP. You'll need to Popup property set to Yes. NOTE: Access 2000 and up required the Modal property to be set to yes also, but that caused this code to not work. The two lines that are commented with 'Not needed in Access 97 are what I used to get around having to set the Modal property to Yes. Drew