473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

66 64KB
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!

2 11335
twinnyfo
3,653 Expert Mod 2GB
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
32,556 Expert Mod 16PB
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

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

Similar topics

3
by: Simon East | last post by:
We recently upgraded from Windows 98 to Windows XP (clean install), but still required to edit Access 97 databases and so have kept Access 97. We installed Word XP and Excel XP, then Access 97. ...
4
by: A.M | last post by:
Hi, How can I bring up a WinForms application window among several other windows? I have tried Show() method, but it doesn't always work. Thanks, Alan
22
by: Nina | last post by:
While user is working on a windows application, at same time he or she launches another instance of the same application. Will this affect the global variables in the first instance of this...
2
by: Tosch | last post by:
I have an application that may not be the top window and is checking new messages every minute. If I find a new message I want to display a form with the new message and bring this form at the top...
3
by: RBarryYoung | last post by:
How can I get the following two features in the same program in VS2005?: 1) Access to the command-line arguments (cmdArgs()) that started my App. 2) Shutdown Mode = "When last Form exits". ...
1
by: lavu | last post by:
I currently have a C# windows Application . I would like this App to work through an command line interface also. I would like to specify command line params, which should start the app and process...
0
by: Milan | last post by:
I have a dataset that has DBNull in certain columns, now when I write out this one to XML, I only get the columns as elements that do have data in it. However I do need also the empty colums as empty...
4
by: Gav | last post by:
Hi, I am writing a windows form application (C#) which access's data from an SQL server. The SQL server is using windows authentication only. At the moment I have to grant the domain users...
5
by: Paul | last post by:
Is it possible to display a form inside another form? What component should I use?
0
by: Developer111 | last post by:
I am developing an application having multiple screens appearing one after another using Vs2008 on Windows Xp(sp3) in vb.net. My requirement is to bring some screens (windows form) in front of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.