Identify Access instance-Bring it to forefront (1 Viewer)

JohnPapa

Registered User.
Local time
Today, 14:11
Joined
Aug 15, 2010
Messages
954

JHB

Have been here a while
Local time
Today, 13:11
Joined
Jun 17, 2012
Messages
7,732
...
still I cannot get it to work
Do you get an error, or does the wanted MS-Access application not come in front?
What code do you've to call the function?
 

JohnPapa

Registered User.
Local time
Today, 14:11
Joined
Aug 15, 2010
Messages
954
Hi JHB,

To provide some info

To call the sw for DentistX I use the following in the icon target

Code:
"C:\Program Files\Common Files\Sagekey Software\StartAccess3_2013.exe"  "X:\Vd5.accde" /runtime
To call the sw for DentistY I use the following in the icon target

Code:
"C:\Program Files\Common Files\Sagekey Software\StartAccess3_2013.exe"  "Y:\Vd5.accde" /runtime
If I use for DentistX

Code:
[COLOR=#2a2a2a][FONT=Segoe UI]Application.FollowHyperlink "x:\vd5.mde"[/FONT][/COLOR]
it works, that is when the sw is open and I execute the code, it brings the instance to the foreground, but this requires A2013. I want to use the above command which works with the Runtime to do the same. Hope the explanation helps.
John
 

JohnPapa

Registered User.
Local time
Today, 14:11
Joined
Aug 15, 2010
Messages
954
Have not figured this one out yet but have managed to simplify the requirement.

From within an Access application I want to be able to bring to the foreground a Window which is open and is defined by its hWnd property.

I tried to use
Code:
BringWindowToTop (rst!THandle)
essentially using
Code:
Private Declare Function BringWindowToTop Lib "user32" (ByVal _          hWnd As Long) As Long
This works if both forms are in the sane db, but not if I try to open a window outside the calling Access db.

I include below the code which I used for calling form2 from form1 in the same db. The hWnd are stored in Table1.
Code:
 Private Sub CallWindowInSameDb_Click()
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open "Table1", CurrentProject.Connection, adOpenKeyset, adLockPessimistic
rst.MoveFirst
BringWindowToTop (rst!THandle)
End Sub
Does anyone know why it does not work outside the Access Db, or are there any other suggestions on how to handle this?

Thanks,
John
 

vbaInet

AWF VIP
Local time
Today, 12:11
Joined
Jan 22, 2010
Messages
26,374
You want something simpler?

Code:
VBA.AppActivate "Title of your access db"
... that is the title you set in the "Application Title" property.
 

JohnPapa

Registered User.
Local time
Today, 14:11
Joined
Aug 15, 2010
Messages
954
Thanks vbaInet,

I used on Load of form
Code:
Private Sub Form_Load()
CurrentDb.Properties!AppTitle = "1"
End Sub

where "1" is the serial number of the specific Access db and tried to use from a different Access db

VBA.AppActivate "1"

It tells me "Run-time error '5': Invalid procedure call or argument"

John
 

vbaInet

AWF VIP
Local time
Today, 12:11
Joined
Jan 22, 2010
Messages
26,374
Set the application title manually. Go to Access Options.
 

JohnPapa

Registered User.
Local time
Today, 14:11
Joined
Aug 15, 2010
Messages
954
Thanks VbaInet,

I tried it in A2013 and it works, although I cannot invoke a minimized Db.

So essentially I can set programmatically the Title to the Serial number of the specific Access db (each has a unique Serial number) and call it from my so called switchboard Access using

VBA.AppActivate "Serial number"

Any ideas on how to invoke a minimized Access DB?
 

vbaInet

AWF VIP
Local time
Today, 12:11
Joined
Jan 22, 2010
Messages
26,374
Ok, since you have a reference to your db, make the db maximized and then call AppActivate. Some aircode:
Code:
dim objApp as access.application

set objApp = getobject(, "Path to db")

objApp.docmd.maximize

vba.appactivate objapp.currentdb.properties!apptitle
 

vbaInet

AWF VIP
Local time
Today, 12:11
Joined
Jan 22, 2010
Messages
26,374
Or specifically
DoCmd.RunCommand acCmdAppMaximize
 

JohnPapa

Registered User.
Local time
Today, 14:11
Joined
Aug 15, 2010
Messages
954
I am doing something wrong. The following opens a new instance of the db and goes to a specific form

Code:
Dim objApp As Object
strDB = "C:\ASwitch\Database1.accdb"
Set objApp = GetObject(strDB, "Access.Application")
DoCmd.RunCommand acCmdAppMaximize
 objApp.DoCmd.OpenForm "Form1"
'objApp.DoCmd.Maximize
 'VBA.AppActivate "1"
It is not maximized and I do not use
Code:
VBA.AppActivate "1"
it is commented out

Any help welcome.
 

vbaInet

AWF VIP
Local time
Today, 12:11
Joined
Jan 22, 2010
Messages
26,374
You need to use the reference to the app in order to maximize it, as shown in my initial post:

objApp.DoCmd.RunCommand acCmdAppMaximize
 

JohnPapa

Registered User.
Local time
Today, 14:11
Joined
Aug 15, 2010
Messages
954
The following appears to work

Code:
Dim objApp As Object
strDB = "C:\ASwitch\Database1.accdb"
Set objApp = GetObject(strDB)
objApp.DoCmd.RunCommand acCmdAppMaximize
VBA.AppActivate "1"

Many thanks for your help which was invaluable.

I will try it out in the next few days and will mark as answer.

John
 

JohnPapa

Registered User.
Local time
Today, 14:11
Joined
Aug 15, 2010
Messages
954
As promised I did some testing and came up with this

Code:
Dim strDB As String
strDB = "V:\Vd5.accdb"
 Dim objApp As Object
Set objApp = GetObject(strDB)
objApp.DoCmd.RunCommand acCmdAppMaximize
 On Error GoTo ExecuteShell
VBA.AppActivate "3"
Exit Sub
 ExecuteShell:
Dim strDB2 As String
strDB2 = "C:\Program Files\Common Files\Sagekey Software\StartAccess3_2013.exe " & strDB & " /runtime"
retVal = Shell(strDB2, vbMaximizedFocus)
It is assumed that the pathname of the db and the Application title are know. We first try to open using VBA.AppActivate, if this fails we open with the Shell command.
 

Users who are viewing this thread

Top Bottom