Set focus to MS Access database launched using VBA from another database

I have spent countless hours on this and cannot find a solution.  I am opening a Microsoft Access database from another MS database. When the second database opens, it minimizes on screen.   No matter what I do, I can't seem to get the code in the first database to relinquish focus to the second database.  Below is my calling code

Dim strPath As String
Dim accapp As Access.Application
strPath = CurrentProject.Path & "\EZPROHR.accde"
 
Set accapp = New Access.Application
accapp.Visible = True

accapp.OpenCurrentDatabase strPath

accapp.Run "SetHRVariables", EZ.strSessionID, EZ.EmployeeID, EZ.SecurityLevel, Forms!switchboard!EmpAccess, Forms!switchboard!ClientAccess

Stop  '  the stop is only here for troubleshooting.  When the code gets to the Stop, the second database in on the screen with the focus

ExitSub:
    Exit Sub  ' when the code exits the routine, then the second database minimizes to the task bar.

I have already tried running  accapp.RunCommand acCmdAppMaximize  from the calling application and
     DoCmd.RunCommand acCmdAppMaximize on the second database when it launches.
    I've tried docmd.maximize on a loading form in the second database and accapp.docmd.maximize from the calling app
I've tried using SendKeys "% X"
I've tried dozens of variations of coding on timer events of loading forms etc.  Nothing has worked.
Mel BrooksCITOAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
You could try opening the other application with Shell  - using the full command, like:

"d:\folder\msaccess.exe " & strPath

Open in new window


and parameter WindowStyle set to vbNormalFocus.

This second instance should run completely independently of the first instance.
John TsioumprisSoftware & Systems EngineerCommented:
Well  this was tricky but i think have found a solution...
I used the code from here  SetAppTitle in order to create a new AppTitle property for you current application (CurrentDb)
So your code needs that modification
Dim strPath As String
Dim accapp As Access.Application
strPath = CurrentProject.Path &  "\EZPROHR.accde"
 
Set accapp = New Access.Application
accapp.Visible = True

accapp.OpenCurrentDatabase strPath
' ---- Your Code on the "remote" Access
SetAppTitle "The Title you want to set to Your Application"

AppActivate CurrentDb.Properties("AppTitle").Value

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
The following article may be of some interest.

https://www.experts-exchange.com/articles/28861/Obtaining-an-object-variable-for-a-running-instance-of-Microsoft-Access.html

  It shows you how to move back and forth between two instances of Access.  Specifically:

        BringWindowToTop (lngHWND)
        lngReturn = ShowWindow(lngHWND, 3)

 Calls.  

 Note this is similar to John's suggestion, but rather than setting an app title, it just "marks" a window and then switches to it by finding that mark.

Jim.
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
BTW, this article:

https://www.experts-exchange.com/articles/2104/Avoiding-running-multiple-instances-of-an-application.html

 Might make that process a bit clearer.  It shares some of the code as the first article I posted (marking a window and then switching to it).

Jim.
Mel BrooksCITOAuthor Commented:
Thanks so much for your assistance.  After doing a lot more playing around with this, I found that I could add this one line of code to the load event of the initial form in the second database that is being called and then it took the focus like I wanted:

AppActivate CurrentDb.Properties("AppTitle").Value
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.