B
Billy
I'm opening Access XP runtime instance from Excel over Shell command. I
set in code that window should be hidden. I really don't see window in
task bar but if I check with acApp.Visible I got that is visible.
My problem is that I have to check if existing instance of Accees is
opened by user or by my application. And If is open by my app then I
have to close it otherwise I leave openend when I close my app.
Here is the example code which return me wrong result:
General declaration section:
---
Public acApp As Object
Public db As DAO.Database
---
My test Sub:
---
Sub TestOpenInstance()
Dim x As Long, strDbName As String
strDbName = "C:\Temp\dbTemp.mdb"
x = Shell("C:\Temp\Msaccess.exe " & Chr(34) & strDbName & Chr(34) &
"/Runtime", vbHide)
Set acApp = GetObject(strDbName)
Set db = acApp.CurrentDb
Debug.Print "AC instance dbTemp Opened"
'Check if instance exists and if is visible
On Error Resume Next
Set acApp = GetObject(, "Access.Application")
If Err.Number = 0 Then 'AC running
Debug.Print "Is Visible: " & acApp.Visible
Else
Debug.Print "AC not Running"
End If
Err.Clear
End Sub
---
Using some global variables to retain state is not an option in that
case. Because state is lost in case of reset of the project. If will
correct instance exist in memory I want to use that existing one.
Do I checking this on the wrong way or I have to use some other method
to get that answer if is Access window is visible or not?
Billy
set in code that window should be hidden. I really don't see window in
task bar but if I check with acApp.Visible I got that is visible.
My problem is that I have to check if existing instance of Accees is
opened by user or by my application. And If is open by my app then I
have to close it otherwise I leave openend when I close my app.
Here is the example code which return me wrong result:
General declaration section:
---
Public acApp As Object
Public db As DAO.Database
---
My test Sub:
---
Sub TestOpenInstance()
Dim x As Long, strDbName As String
strDbName = "C:\Temp\dbTemp.mdb"
x = Shell("C:\Temp\Msaccess.exe " & Chr(34) & strDbName & Chr(34) &
"/Runtime", vbHide)
Set acApp = GetObject(strDbName)
Set db = acApp.CurrentDb
Debug.Print "AC instance dbTemp Opened"
'Check if instance exists and if is visible
On Error Resume Next
Set acApp = GetObject(, "Access.Application")
If Err.Number = 0 Then 'AC running
Debug.Print "Is Visible: " & acApp.Visible
Else
Debug.Print "AC not Running"
End If
Err.Clear
End Sub
---
Using some global variables to retain state is not an option in that
case. Because state is lost in case of reset of the project. If will
correct instance exist in memory I want to use that existing one.
Do I checking this on the wrong way or I have to use some other method
to get that answer if is Access window is visible or not?
Billy