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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keeping MS-Access Application Window on Top

Status
Not open for further replies.

sxschech

Technical User
Jul 11, 2002
1,033
US
After some searching, found code that can keep the Access window on top. I'm using this because when I run code to send reports to PDF, acrobat window comes on top and the focus doesn't get set back to Access, so without clicking on the access window occasionally, I can't tell when the code has completed, even though I have a message box to say it has finished. Since the code was cobbled together from three sources, and don't really know about API's can't say for sure if I implemented it right other than it seems to work for my purpose. The code came from mostly from Microsoft and a piece from xtremevbtalk.

Put the following in a code module:

Code:
'Found NoTopMost, which undoes the Window on Top from [URL unfurl="true"]http://www.xtremevbtalk.com/archive/index.php/t-94578.html[/URL]

'[URL unfurl="true"]http://support.microsoft.com/kb/210500[/URL]
'   1. Add the following API declarations to your Global Declarations section:

      Declare Function FindWindow% Lib "user32" Alias "FindWindowA" _
                                                (ByVal lpClassname As Any, _
                                                 ByVal lpCaption As Any)

      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
                        

'   2. Add the following Constants to your Global Declarations section:

      Global Const HWND_TOPMOST = -1
      Global Const HWND_NOTOPMOST = -2
      Global Const SWP_NOSIZE = &H1
      Global Const SWP_NOMOVE = &H2
                        

'   3. Type the following function:

      Function Float_Main()
         Dim X&, Hwnd%
        ' X = Shell("CALC.EXE", 1)
         Hwnd% = FindWindow%("omain", 0&)

         Call SetWindowPos(Hwnd%, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or _
            SWP_NOSIZE)
      End Function

 Function UnFloat_Main()
         Dim X&, Hwnd%
        ' X = Shell("CALC.EXE", 1)
         Hwnd% = FindWindow%("omain", 0&)

         Call SetWindowPos(Hwnd%, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or _
            SWP_NOSIZE)
      End Function

Then in your code call the Float before the point you want to keep Access on top and UnFloat after that has been done so that window functionality is restored, otherwise Access will remain on top from then on, which could be problematic for doing non access stuff.
 
Hey man,

I'm having the reverse problem so maybe you can help me out.

I want to keep an access form on top of an internet explorer, so i set the form.hwnd to topmost using setwindowpos above. However, if you click on or move the pop up, the access application is automatically brought in front of the ie. I want the user to be able to reposition the pop up over the ie as they wish and use it without it going back to the main application window. You have any idea on how to do this.

thx
CN

 
Tried playing around a bit and no luck so far. Have you considered, if your security allows it, to put a web browser control on a form in your access database, then you would probably be able to keep the pop up on top and move it around without having the application window in the way since it will all be in the same window. Unfortunately, my security isn't set up for this so couldn't test it.
 
Not sure if this will help.
thread707-1470989
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top