How to check if instance of application is already open?

GBalcom

Much to learn!
Local time
Yesterday, 20:23
Joined
Jun 7, 2012
Messages
460
I have an app that is opened automatically. Noticing that through some glitch in my process, it has been possible for it to open more than once.

I'd like to add some code on startup to prevent this.

Seems like application.quit will work, but how to test for the existing instance?
 
Isd it a split database with multiple FEs?

Things you could consider (untested)
1. Only allow the app to be opened exclusively
2. Have a single record, single field table with a boolean value
Set that value true when opened and false again when closed.
Before doing that, check the field value and if already true, quit the app

I do something similar to item 2 with a boolean Kickout field to prevent users opening an app when it has been closed for maintenance
 
Last edited:
isladogs,
Thank you for the quick reply. I'm pursuing option #1 right now, as that would be very simple! I appreciate it!
 
You're welcome.
I don't know how well the exclusive approach will work
However, if it helps I have code to check whether an app has been opened exclusively and if not close it.

I do know the second method works and its also simple to setup.
 
isladogs,
Thank you for the quick reply. I'm pursuing option #1 right now, as that would be very simple! I appreciate it!
Pardon me but I thought approach #2 would be much simpler than approach #1, but that's just me. Another approach similar to #2 but a bit more complicated is to generate a text file in some "unknown" (to the user) folder and kill it when the app closes. On startup, check if the file exists and quit the app if it does.
 
Hi Paul
I believe those approaches assume the app is being opened multiple times on the same machine. They wouldn't prevent anyone opening it on another PC.
 
Hi Paul
I believe those approaches assume the app is being opened multiple times on the same machine. They wouldn't prevent anyone opening it on another PC.

True. I was reading it as the o/p did not want a second instance on the same computer.?

Apologies if I misunderstood.
 
Good point, Colin.

The GetObject function MIGHT do it in certain rare cases, but I think the complexity of the rare cases pretty much prevents it from being useful. At least IN THEORY since you can provide a path to your app when using GetObject, you could provide a path including a node name. But you would need to know every potential node where it COULD run AND you would have to be running as a network admin (or more) to be able to look into another machine anyway. Technically, you could perhaps do it - but practically, in most managed domains, you would never have permission to do it.

Therefore, using something internal to the DB - like a single-record BE table - is probably going to be the only reliable way to get this effect. Which falls under one of my favorite bits of advice: Access won't tell you anything you didn't tell it first. Want Access to tell you if something is in use? Have tje Access function that uses that something tell Access it is in use. Which means "in a table in the BE" due to scope issues.
 
Re-reading the original question, though, it is not clear whether the question is "on the same computer."
I guess you guys are on the right track, but right off the hop I'm thinking "why does everyone assume this is Access? Maybe the 'app' is Word, Outlook, Excel or who knows what." Neither the question title, forum branch or post itself makes that clear.
 
Time for the OP to provide some answers.... :D

Assuming it is Access, method #2 will work on the same computer whether split or not AND will still work on multiple PCs with a split DB and a single record Boolean field table in the BE.
I know because I've used that idea in my 'kickout' feature for 20+ years
 

Users who are viewing this thread

Back
Top Bottom