Results 1 to 4 of 4
  1. #1
    billpennock is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    4

    using app.opencurrentdatabase the new database opens in background

    I am taking over the maintenance of another persons code. They have form that opens databases from buttons. The code to open the database is

    Set appAccess = CreateObject("Access.Application")

    ' Open database in Microsoft Access window.
    strDB = strDB + FilePath 'fq name of the new database
    DoCmd.RunCommand acCmdAppMinimize
    appAccess.OpenCurrentDatabase strDB
    appAccess.RunCommand acCmdAppMaximize

    When the new database opens a form is shown immediately with a combobox filled from a query. the only code in that form is event code on after change on the box and that works fine
    The problem is when the new database opens it is shown in the background. In the three jpgs I select database collection.accdb to start things, then payroll in the next picture
    the third picture shows the problem, the form is there but behind the file explorer window I started with.
    Click image for larger version. 

Name:	1fileexplorer.JPG 
Views:	8 
Size:	54.8 KB 
ID:	31567
    Picture #1 select database collection to start access


    Click image for larger version. 

Name:	2selectAnotherDatabase.jpg 
Views:	8 
Size:	30.6 KB 
ID:	31566
    Picture # 2 select payroll which runs the code above





    Click image for larger version. 

Name:	3theComboboxform is there but background.JPG 
Views:	8 
Size:	72.2 KB 
ID:	31565
    Picture #3 payroll initial screen is there but in the background

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    If you do not need to control Access programatically then there's no need to open it using that code.
    Instead use the Shell to command the window to come to the front

    usage:
    OpenAccessDb "c:\arcadia\Payroll.accdb"

    paste the code below into a module:
    Code:
    sub OpenAccessDb(byval pvDb)
    call Shell("C:\Program Files\Office16\Access.EXE " & pvDb, 3 )
    end sub



    vbHide=0
    vbNormalFocus=1
    vbMinimizedFocus=2
    vbMaximizedFocus=3
    vbNormalNoFocus=4
    vbMinimizedNoFocus=6

  3. #3
    billpennock is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    4
    thanks that set me on the right path. In addition the front end is pushed to multiple machines and i don't have control over where access.exe (which is msaccess.exe by the way) is. so....

    Code:
    sub OpenAccessDb(byval pvDb)
    dim strAccessPath as string
    dim strQuote as string
    
    strQuote = chr(34)
    pvDb = strQuote + pvDb + strQuote
    strAccessPath = syscmd(acSysCmdAccessDir) & "msaccess.exe"
    strAccessPath = strQuote + strAccessPath + strQuote
    call Shell(strAccessPath & " " & pvdb, 3)
    
    end sub
    probably could have shorted up the lines a bit of course but this works

  4. #4
    billpennock is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    4
    After I did the above I realized I wanted the calling database to wait till the called database was finished so i changed the call to use

    Code:
    dim waitforreturn as boolean
    dim app2call as object
    set app2call = vba.createobject("WScript.shell")
    waitforreturn = true
    app2call.run straccesspath & " " & pvdb, 3, waitforreturn

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

Similar Threads

  1. Replies: 5
    Last Post: 10-09-2017, 03:09 PM
  2. Replies: 9
    Last Post: 05-03-2014, 03:36 PM
  3. Replies: 2
    Last Post: 05-17-2013, 12:40 PM
  4. message pop up for users when database opens
    By ecalvert47462 in forum Access
    Replies: 8
    Last Post: 10-18-2012, 11:39 AM
  5. Auto Sort ID Field When DataBase Opens
    By lyndon.pace in forum Reports
    Replies: 1
    Last Post: 04-08-2011, 10:06 AM

Tags for this Thread

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