Is File Open

A

alex

Is File Open

Hello,

Using Access ’03…

I have code in my db that, when executed, looks to see if it (the
file) is already opened. If so, provide msgbox and close; if not,
open the file.

The code looks for the presence of the ldb. This works, but when the
db is improperly closed (due to a host of issues; network problems,
etc.) the ldb exists when the file is not actually opened.

I then wrote this code:
----------
On error goto ldb_Err

Dim ldbName As String
ldbName = "File.ldb"

'check to see if ldb exists on drive

If Len(Dir("Q:\" & ldbName)) > 0 Then 'file exists
Kill ("Q:\" & ldbName) 'delete the ldb
Exit Function
Else
'file is not open continue to next function
End If

Exit Function

ldb_Err:
If Err.Number = 70 Then 'could not delete the ldb because it's
truly open
MsgBox "File is already open!"
DoCmd.Quit acQuitSaveNone
Else
MsgBox "Enter Msg here" 'some other error occurred
DoCmd.Quit acQuitSaveNone
End If
----------
This code also works, but I get a little nervous killing files. Is
there another way to check to see if an mde is open, or is the code
above the best way to accomplish the task?

Thanks,
alex
 
D

Daryl S

Alex -

Sometimes when the .ldb file is there "in error", then opening and closing
the database will remove the .ldb. Try that before even thinking of killing
files.

If that doesn't work, then we use the Access LDB Viewer to see who might
still be on. (You can search on line to find this.) If it shows someone
still logged in, then we contact the person just in case they are still
logged on. If they are not, then they can log in and out, and that usually
clears up the problem.
 
A

alex

Alex -

Sometimes when the .ldb file is there "in error", then opening and closing
the database will remove the .ldb.  Try that before even thinking of killing
files.  

If that doesn't work, then we use the Access LDB Viewer to see who might
still be on.  (You can search on line to find this.)   If it shows someone
still logged in, then we contact the person just in case they are still
logged on.  If they are not, then they can log in and out, and that usually
clears up the problem.

--
Daryl S














- Show quoted text -

Hi Daryl, thanks for responding...
My problem is that I don't want the db to open (again) if it's already
open, so I cannot open/close the db to clear the ldb.
I could write a msgbox that tells them to look for the ldb if the db
is truly not open, but that's a pain!
alex
 
D

Daryl S

What environment are you in? Is this a front-end application, a stand-along
application, is it multi-user, etc.? How Access-knowledgeable are your
users? You need to weigh the risk of corrupting the database if someone else
is in it when you kill the .ldb file. If it is multi-user, and there is a
..ldb file, then I would still recommend using the ldb Viewer to see who is in
before taking action...
 
A

alex

What environment are you in?  Is this a front-end application, a stand-along
application, is it multi-user, etc.?  How Access-knowledgeable are your
users? You need to weigh the risk of corrupting the database if someone else
is in it when you kill the .ldb file.  If it is multi-user, and there is a
.ldb file, then I would still recommend using the ldb Viewer to see who is in
before taking action...  
--
Daryl S






- Show quoted text -

Daryl,
It's a multi-user environment; i.e., each user has his/her own front-
end mde (I'll never run the risk of corruption by killing a user's ldb
file...). Also, I don't care who's in the db; it's read only and the
user creates a copy of the data when they enter the db; i.e., all
users have their own data. The mde gets replaced everytime they open
the file.

What's the ldb viewer anyway?
 
D

Daryl S

Alex -

The ldb Viewer is an application that lets you see into the .ldb file. It
is great for multi-user environments to tell who is in the database, and who
has gotten out since the last .ldb was created. You can search for it on the
web. If you are only looking at the front-end on a user's desktop, then this
will not be helpful.

Now I am confused as to your application - if you are testing to see if it
is open from within the app, when would it not be open? What is it you are
trying to prevent?
 
A

alex

Alex -

The ldb Viewer is an application that lets you see into the .ldb file.  It
is great for multi-user environments to tell who is in the database, and who
has gotten out since the last .ldb was created.  You can search for it on the
web.  If you are only looking at the front-end on a user's desktop, then this
will not be helpful.

Now I am confused as to your application - if you are testing to see if it
is open from within the app, when would it not be open?  What is it youare
trying to prevent?

--
Daryl S







- Show quoted text -

Daryl,
I'm trying to prevent the user from opening the db a second time...I'm
not testing from within the app; i'm testing from within an executable
file (just happens to be another mde) that copies a fresh mde into the
users personal network space and then opens it. If the "executable
mde" sees that the ldb exists, it knows not to copy the fresh mde and
then try to open it (again in this case)! It's been so long, I don't
remember the specific error(s) that occur if this is allowed to
happen. As you know, you can't have two files with the same name in a
particular folder...and since the file is open, the new (fresh mde)
cannot overwrite the old one (which is what happens when the "old" mde
is closed). The process works pretty well when I can ID that the ldb
exists or not...
alex
 
D

Daryl S

Alex -

OK, so you may have the best solution. I don't know another way to tell if
it is open, as I don't know of any collections object that holds open
applications, though it seems the operating system would have to know that.
Might be worth checking the Windows discussion groups to see if they can
identify the list of open 'documents'...
 
A

alex

Alex -

OK, so you may have the best solution.  I don't know another way to tell if
it is open, as I don't know of any collections object that holds open
applications, though it seems the operating system would have to know that.  
Might be worth checking the Windows discussion groups to see if they can
identify the list of open 'documents'...

--
Daryl S






- Show quoted text -

Thanks Daryl for your help...I'll do that.
alex
 

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