Mitsules, Mark
Mark.Mitsules at ngc.com
Thu Oct 9 13:08:12 CDT 2003
Excellent. If I were to make an observation...could similar code be placed in a module and called from checkboxes located on multiple forms...toggle on/off as desired? Don't waste any time on it...just curious given the problems you've overcome thus far. Mark -----Original Message----- From: Drew Wutka [mailto:DWUTKA at marlow.com] Sent: Thursday, October 09, 2003 1:54 PM To: 'AccessD at databaseadvisors.com' Subject: [AccessD] Always On Top (Final Solution) 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 _______________________________________________ AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com