none
Bring Access Back to the top RRS feed

  • Question

  • I am having an issue trying to bring Access back to the top in the middle of a procedure:

        Shell ("C:\Program Files\Google\Chrome\Application\chrome.exe -url " & URL)
            
        varFile = "PowerUsagebyLocation_circuit_*.csv"
        
        WaitSeconds (3)
        
        AccessOnTop

    AccessOnTop calls the following:

    Option Compare Database
    Option Explicit
    
    Private Declare Function apiBringWindowToTop _
        Lib "user32" Alias "BringWindowToTop" _
        (ByVal hwnd As Long) _
        As Long
    
    Sub AccessOnTop()
    
        apiBringWindowToTop (hWndAccessApp)
    
    End Sub

    When I test the sub in the immediate window, it appears to work.  I've even tried using the FindWindow API using OMain as the Class name with a vbNullString.  That didn't work either after running the shell.

    Any suggestions would be great.  Thanks.

    Thursday, March 31, 2016 1:40 PM

Answers

  • This code works:

    Option Compare Database Option Explicit Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long '********************************************************** '* Run something and then restore focus to Access window '* Private Sub RunSomething() Dim URL As String Dim I As Integer URL = "google.com" Shell ("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe -url " & URL) For I = 1 To 300 'Allow threads to run DoEvents Next I '* '* Your code here ... '* ' ...... ' ......

    'Restore Access window
    Call AccessOnTop End Sub '************************************************* '* Restore focus to current Office Application '* Sub AccessOnTop() SetForegroundWindow (hWndAccessApp) End Sub



    Best regards, George

    • Marked as answer by Tim.K.eq Monday, April 4, 2016 10:30 AM
    Sunday, April 3, 2016 3:46 PM

All replies

  • Try this:

    Shell "your_command", vbNormalNoFocus


    -Tom. Microsoft Access MVP

    Thursday, March 31, 2016 2:04 PM
  • Tried these:

    Shell ("C:\Program Files\Google\Chrome\Application\chrome.exe -url " & URL), vbNormalNoFocus

    and

    Shell ("C:\Program Files\Google\Chrome\Application\chrome.exe -url " & URL), vbMinimizedNoFocus

    and both had the same results.  Chrome stays on top.

    Also tried without the ( )
    • Edited by Tim.K.eq Thursday, March 31, 2016 2:31 PM
    Thursday, March 31, 2016 2:20 PM
  • Try adding DoEvents right after the call to AccessOnTop.

    Regards,

    Albert D. Kallal (Access MVP)

    Edmonton, Alberta Canada

    Saturday, April 2, 2016 9:42 PM
  • This code works:

    Option Compare Database Option Explicit Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long '********************************************************** '* Run something and then restore focus to Access window '* Private Sub RunSomething() Dim URL As String Dim I As Integer URL = "google.com" Shell ("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe -url " & URL) For I = 1 To 300 'Allow threads to run DoEvents Next I '* '* Your code here ... '* ' ...... ' ......

    'Restore Access window
    Call AccessOnTop End Sub '************************************************* '* Restore focus to current Office Application '* Sub AccessOnTop() SetForegroundWindow (hWndAccessApp) End Sub



    Best regards, George

    • Marked as answer by Tim.K.eq Monday, April 4, 2016 10:30 AM
    Sunday, April 3, 2016 3:46 PM
  • Thanks George,

    I used your concepts for the code I have already and it worked perfectly.

    Monday, April 4, 2016 10:30 AM
  • I would suggest that you don't need + use 300 doEvents, but try a "few" with a delay. However at this point in time the "key concept" was you needed DoEvents to allow the Access event que to execute the maximize command.

    Great question, and George's follow up cracked this egg for us!

    Albert D. Kallal (Access MVP)

    Edmonton, Alberta Canada

    Monday, April 4, 2016 3:17 PM
  • Albert,

    The reason for many DoEvents is that (in this case) Chrome needs ample time to start and when started Access is still in the loop. I'm sure there are other variants to my suggested code.


    Best regards, George

    Monday, April 4, 2016 3:21 PM