Results 1 to 10 of 10
  1. #1
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79

    Form on top of screen

    Hi,



    I have written code to force shut down of everyone using the database. I am showing the user a warning in picture below. However, if the user is working in another application for the moment, like Excel, the warning form isn't shown in top of sceeen. Anyone has a suggestion how to get the warning form always on top of screen? I have tried to use Modal & Popup but no luck.

    Click image for larger version. 

Name:	Capture.PNG 
Views:	27 
Size:	6.6 KB 
ID:	28043

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    you cant. If they arent in the app , they cant get the message.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    There are about a thousand Windows API calls. One or a combination of them might do the trick. What comes to mind is FindWindow (in conjunction with BringWindowToTop) however I'm not sure if your form would come to the top of its application or if it relates to the whole system. It might even bring the application itself to the top. Your code might have to assign the form window handle to a module level public variable so that the API call can easily figure out which window to raise.

    Google ms access vba API popup or something like that. You could start here also.
    Last edited by Micron; 03-29-2017 at 12:19 PM. Reason: spelin
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79
    Thanks,

    Following code works to bring Access on top of screen if I:
    - Step AccessOnTopOfScreen() by using buttons F5 or F8

    However, if I invoke AccessOnTopOfScreen() in my normal code, Access isn't shown on top of screen. But, adding a Breakpoint on:
    lTest = BringWindowToTop(lhWndApp)
    and continue by either F5 or F8, then it works in my normal code.

    Any thoughts why it doesn't work in my normal code? I get no error message. Variable lTest resturns always 1 which indicates that BringWindowToTop() works. But still Access isn't in top of screen.

    Code:
    'Show Application/Window on top of screen
    Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
    
    Sub AccessOnTopOfScreen()
    'Show Access on Top of Screen
        Dim lhWndApp As Long
        Dim lTest As Long
        
        lhWndApp = Application.hWndAccessApp
        lTest = BringWindowToTop(lhWndApp)
        
    'Verification
    '**************************
    Debug.Print lTest
    '**************************
    End Sub

  5. #5
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79
    Hi,

    This fix solved my issue. Activating Access before I show the warning by using AppActivate().

    Code:
    '...
    Call AppActivate(CurrentDb.Properties("AppTitle"))
    DoCmd.OpenForm "FWarning"
    '...
    Still interested though why BringWindowToTop() isn't working in my previous response above. Can be useful in other situations.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Seen this sort of behavior before. I never verified, but I reckoned that since the vb editor is part of the Access app, the app is active if you're stepping through code.
    Thanks so much for posting the solution! If you could post the relevant final code, that would be great. Someone else may benefit from it down the road.

  7. #7
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79
    Hi,

    Attached is my "Force Shut Down". Maybe its useful for someone else.

    It works like this:

    1. Open the form "FShutDown"
    2. Check 'Force Shut Down'
    3. Click OK. Countdown now starts to shut down.

    Click image for larger version. 

Name:	Activate.PNG 
Views:	15 
Size:	3.0 KB 
ID:	28072

    User gets a warning every minute until shut down. User can choose to click OK or not. Countdown continues in background.

    Click image for larger version. 

Name:	CountDown.PNG 
Views:	15 
Size:	6.6 KB 
ID:	28073

    Designer/Administrator can choose to Cancel the forced shutdown before countdown is reached. Just open the form "FShutDown" again an uncheck "Force Shut Down". Click OK.

    Click image for larger version. 

Name:	Dectivate.PNG 
Views:	15 
Size:	3.1 KB 
ID:	28074

    After a while all users gets following confirmation:

    Click image for larger version. 

Name:	Confirm_Deactivate.PNG 
Views:	15 
Size:	6.5 KB 
ID:	28075
    Attached Files Attached Files

  8. #8
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    Thank you for posting your working solution for us!

  9. #9
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Ditto. Had a look at your db; a slight compatibility issue for me, but don't think that's the reason I don't see an api call to bring the app window to the top. I do see a call to an application level method that I'm not familiar with. Given that your db seems to work**, I guess that's the reason it works.

    **except that the compatibility issue does prevent the db from actually closing without me acknowledging the issue.
    Notes:
    - There's no need for an autonumber id field in tshutdown. If you end up with a new id number, you'll have to edit your code. I think I'd just do DLookups like
    DLookup("TimeToShutdown_Minutes","[_tShutdown]")
    - Suggest you don't start object names with special characters (even underscore) and especially not numbers (not that you are).

    Thought I might play with a version that doesn't use a table at all...

  10. #10
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Forget that. Just realized it would be of no use in a split db, which this probably is and ought to be.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. centre form on screen
    By Jen0dorf in forum Access
    Replies: 6
    Last Post: 11-05-2015, 01:00 PM
  2. Best screen resultion for most common screen sizes
    By sjs94704 in forum Database Design
    Replies: 3
    Last Post: 05-26-2015, 06:12 AM
  3. Expand Form to fit screen?
    By offie in forum Forms
    Replies: 1
    Last Post: 08-05-2014, 03:23 PM
  4. bar on form screen
    By everette in forum Access
    Replies: 2
    Last Post: 10-08-2011, 12:10 PM
  5. Replies: 11
    Last Post: 06-05-2011, 09:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums