Why I got that instance is visible if is not?

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
 
M

MacDermott

Perhaps you could check whether there is an Access instance running
**before** you open your instance?

However, you can have multiple instances of Access XP running on your PC,
and (I think) your code will always create a new one.
So just always close the one you opened - no need to be concerned about
other instances.
 
B

Billy

Exactly that I would like to achieve. But If Access window is visible
on the screen then I will open my own instance (because user can run
for example Access 2000 but my app use XP Runtime) otherwise I will use
existing one (when I check if version is Ok). Problem is if came to any
unhandled error the project is reset (variable are reset) and then stay
"orphan" hidden instances of Access.

So Q is how to get answer over code that instance is hidden (not
visible in taskbar). If I open instance with Shell is not visible by
the user but is visible by the "Application.Visible" property and I
don't know why is that happen and I don't know what to use instead of
that to get that info?
 
M

MacDermott

I think you can create a named instance of Access XP with code like this:
set aXP=CreateObject("Access10.Application")
I think this would stay set, even if an unhandled error happens...
 
B

Billy

That doesn't work with Access Runtime version.
So my problem is still when I open hidden Access instance with Shell
function. If I could get back from some property True if Access window
is visible on the screen and False if is not. How to do that, that is
my problem??
 
M

MacDermott

How about my original suggestion that you check for the existence of other
Access instances before you open yours?
 
B

Billy

Thank's for help Mac. I already found solution for that by checking if
running instance is Runtime.

Regards,
Billy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top