Keep access 2000 window always on top

For a particular Access db, I want to keep my MS Access 200 window always topmost on the desktop - even when it loses focus.  

My access window is already sized and positioned (a low 200x600 profile in the lower left corner).  But now I want it to always stay on top, regardless of all other windows.  Currently, when another window is selected my access window loses desktop focus and jumps behind.  

Thanks
BHRAsked:
Who is Participating?
 
dannywarehamConnect With a Mentor Commented:
Hi again.

Here's how to do from start to finish:

Open a new module.
Paste in this code:


Option Compare Database
Option Explicit
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
Global Const HWND_TOPMOST = -1
Global Const SWP_NOSIZE = &H1
Global Const SWP_NOMOVE = &H2
     
Function TopMost(F As Form)
         Call SetWindowPos(F.hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
                           SWP_NOMOVE Or SWP_NOSIZE)
End Function





'*******************************************************

Now, in the form that you want to "float", add this to the "OnTimer" event (it's in form properties, onthe events tab)

=TopMost([Form])

Set the timer interval as
50

On the "Other" tab, you'll find "Pop up"
Change this to "Yes"

Save and run teh form.
You'll see it floats over all your applications


:-)
0
 
dannywarehamCommented:
OK - you need to be sneaky with this one.

First, set your form to Modal - that ensures that the form is always on top of teh Access window.

Now, you use this:

'This bit in the declarations
Public Declare Function GetActiveWindow Lib "user32" () As Long

'This bit in the timer event
If GetActiveWindow=0 Then
'Not Active, do something
Else
'Active, do something else
End If


This code (above) checks if the Access window is the curerntly viewed window.
0
 
stevbeCommented:
and pray that no other developer used SendKeys or things are gonna start to get wild :-)
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
BHRAuthor Commented:
Thanks, this is a slick way of telling me whether access is topmost or not
However, where I'm stuck is in trying to set/keep the window as topmost

I have been trying to combine two functions...
one that allows me to size/position the access window
(based on http://support.microsoft.com/?kbid=210085)

one that keeps the MS Access window on top of all other application windows
(based on http://support.microsoft.com/default.aspx?scid=kb;en-us;101325)

I can get each one to work separately, but haven't been able to successfully combine them into a single function.
Thanks again!
0
 
dannywarehamCommented:
Try this.
Input teh second links' code into your database as far as "Function Float_Calc()".

Then use this:

'This bit in the declarations
Public Declare Function GetActiveWindow Lib "user32" () As Long

'This bit in the timer event
If GetActiveWindow=0 Then
'Not Active, do something
Dim X&, hwnd%
         X = Shell("CALC.EXE", 1)
         hwnd% = FindWindow%("SciCalc", 0&)

         Call SetWindowPos(hwnd%, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or _
            SWP_NOSIZE)
End If
0
 
Jim Dettman (Microsoft MVP/ EE MVE)Connect With a Mentor President / OwnerCommented:
Hi,

  BHR e-mailed me off-line asking for some help.  Being new to EE, s/he wasn't sure how to proceed as an answer hasn't really been given yet.

  Work on this a bit more (from both sides) and if it still hasn't come to a conclusion, I'll post a link on Expert Notify so others can look at it.

BTW, This may be a re-hash of what's already posted, but it was a different KB # so I thought I'd post:

ACC2000: How to Make Microsoft Access Windows Stay on Top of Other Windows
http://support.microsoft.com/?kbid=210500

  At a brief glance, it sounds like what BHR may be looking for.

Jim.
0
 
dannywarehamCommented:
BHR - how you getting on there...?

:-)
0
 
BHRAuthor Commented:
sorry.  maybe i'm daft, but none of these seems to quite cut it.  

My preferrence so far, is still what I originally had... using function sizeaccess (as described in http://support.microsoft.com/?kbid=210085).  

I've tried the other stuff, but the "topmost" function has two unwanted effects:
1) the window opens full size (where as I want a 200x1000 window in lower left corner of screen)
2) it makes the user unable to open or change focus to any other windows until you close Access down (whereas I want to be able to move around other apps... but keep access on top).

This Access app is for capturing reviews/scores of other documentation (in Word, Excel, etc.).  So I don't want to have to keep pulling it to the front while i'm moving around the other apps.

Thanks again all!
0
 
flavoConnect With a Mentor Commented:
FROM duplicate Q -> http:Q_21393613.html

Here we go.. Just change it from From.hwnd and use the Access Hwnd instead.

    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
                                       
    Global Const HWND_TOPMOST = -1
    Global Const SWP_NOSIZE = &H1
    Global Const SWP_NOMOVE = &H2


    Function TopMost()
    '// Set Access as the top most window
        Call SetWindowPos(Application.hWndAccessApp, HWND_TOPMOST, 0, 0, 0, 0, _
                           SWP_NOMOVE Or SWP_NOSIZE)
    End Function

************************************************************
Just a warning... It wont let you open any other windows (focus on them) until you close Access down.

Dave
0
 
flavoCommented:
oh... Im a little off...
0
 
BHRAuthor Commented:
Got it... several of you were driving me in the right direction using the "topmost" function from MS.   Although I tweaked it a bit to allow me to set size and pos.  I'll split up points for the help.  Thanks.

Here's what I ended up with:

      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
                       

      Global Const HWND_TOPMOST = -1
      Global Const SWP_NOSIZE = &H1
      Global Const SWP_NOMOVE = &H2
      Global Const SWP_NOZORDER = &H4
     
            Function TopMost(F As Form, cx As Long, cy As Long, _
  cHeight As Long, cWidth As Long)

         Call SetWindowPos(F.hwnd, HWND_TOPMOST, cx, cy, cWidth, cHeight, _
                           SWP_SHOWWINDOW)
      End Function
0
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:

  Excellent!

Jim.
0
 
dannywarehamCommented:
Muchas gracias...

Glad to have helped...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.