By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

How to bring a ms access form on top of all windows application

P: 66
My ms access file will capture the Idle time of the user. Now I would like to bring an animation on top of all application when the idle time is more than 5 seconds.

I have used the below code but it is not working for me.

Please advise if there are shell or API can be used to achieve this.


Expand|Select|Wrap|Line Numbers
  1.  
  2. Option Compare Database
  3. Option Explicit
  4.  
  5.  
  6.       Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
  7.                                        ByVal hWndInsertAfter As Long, _
  8.                                        ByVal X As Long, _
  9.                                        ByVal Y As Long, _
  10.                                        ByVal cx As Long, _
  11.                                        ByVal cy As Long, _
  12.                                        ByVal wFlags As Long) As Long
  13.  
  14.  
  15.       Global Const HWND_TOPMOST = -1
  16.       Global Const SWP_NOSIZE = &H1
  17.       Global Const SWP_NOMOVE = &H2
  18.  
  19.       Private Declare Function BringWindowToTop Lib "user32" _
  20.  (ByVal lngHWnd As Long) As Long
  21.  Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
  22.       Function TopMost(F As Form)
  23.          Call BringWindowToTop(F.hwnd)
  24.          SetForegroundWindow Application.hWndAccessApp
  25.       End Function
  26.  
  27. Function TopMost(F As Form)
  28.           Call SetWindowPos(f.hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
  29.                            SWP_NOMOVE Or SWP_NOSIZE)
  30.          SetForegroundWindow Application.hWndAccessApp
  31.       End Function
  32.  
Dec 25 '14 #1

✓ answered by twinnyfo

I use this little function:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Declare Function SetForegroundWindow _
  5.     Lib "user32" _
  6.     (ByVal hwnd As Long) _
  7.     As Long
  8.  
  9. Public Function ActivateAccessApp() As Boolean
  10.     'Brings the DB to the front of all open windows
  11.     Dim appTarget As Access.Application
  12.  
  13.     Set appTarget = GetObject(CurrentDb.Name)
  14.     ActivateAccessApp = _
  15.         Not (SetForegroundWindow(appTarget.hWndAccessApp) = 0)
  16.     Set appTarget = Nothing
  17.  
  18. End Function
Create a new module and place teh above code in it. Just call the function from anywhere in your project like this:

Expand|Select|Wrap|Line Numbers
  1. Call ActivateAccessApp
Hope this hepps!

Share this Question
Share on Google+
2 Replies


twinnyfo
Expert Mod 2.5K+
P: 3,158
I use this little function:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Declare Function SetForegroundWindow _
  5.     Lib "user32" _
  6.     (ByVal hwnd As Long) _
  7.     As Long
  8.  
  9. Public Function ActivateAccessApp() As Boolean
  10.     'Brings the DB to the front of all open windows
  11.     Dim appTarget As Access.Application
  12.  
  13.     Set appTarget = GetObject(CurrentDb.Name)
  14.     ActivateAccessApp = _
  15.         Not (SetForegroundWindow(appTarget.hWndAccessApp) = 0)
  16.     Set appTarget = Nothing
  17.  
  18. End Function
Create a new module and place teh above code in it. Just call the function from anywhere in your project like this:

Expand|Select|Wrap|Line Numbers
  1. Call ActivateAccessApp
Hope this hepps!
Dec 29 '14 #2

NeoPa
Expert Mod 15k+
P: 31,306
A hijack question has now been moved to a new thread called Bring Form to Front.

Please do not post new questions in existing threads.
Apr 13 '19 #3

Post your reply

Sign in to post your reply or Sign up for a free account.