testing if an Access DB is in use or open from an external application

J

Joey

Hi All,

I am developing a stand alone application that synchronizes data from a
local MS Access97 DB with data from an MS Server DB elsewhere. I would
like to test to see if the Access DB is open or in use. Should I have
to parse the directory for the LDB file for the Access DB or is there
some more elegant way to achieve this? Many thanks in advance.

Thanks,
Joey.
 
J

Joseph Meehan

Joey" <"jpk808 said:
Hi All,

I am developing a stand alone application that synchronizes data from
a local MS Access97 DB with data from an MS Server DB elsewhere. I
would like to test to see if the Access DB is open or in use. Should
I have to parse the directory for the LDB file for the Access DB or
is there some more elegant way to achieve this? Many thanks in
advance.
Thanks,
Joey.

I don't know what you mean about parsing the directory for the LDB file,
but you may need to parse the LDB file.
 
?

=?iso-8859-1?Q?J=F6rg_Ackermann?=

Hi,

Joey" <"jpk808[NO SPAM] schreibselte:
I am developing a stand alone application that synchronizes data from
a local MS Access97 DB with data from an MS Server DB elsewhere. I
would like to test to see if the Access DB is open or in use. Should
I have to parse the directory for the LDB file for the Access DB or
is there some more elegant way to achieve this? Many thanks in
advance.

I would use a function like this:

Public Function IsFileOpened(ByVal Pfad As String) As Boolean

Dim FileNr As Integer
Dim ErrNr As Long

On Error Resume Next
FileNr = FreeFile
Open Pfad For Input Lock Write As #FileNr
ErrNr = Err.Number
Close #FileNr
On Error GoTo 0

Select Case ErrNr
Case 0
IsFileOpened = False
Case 70
IsFileOpened = True
Case Else
Err.Raise ErrNr
End Select

End Function

Note:
If the MDB is opened exclusive, ther's no LDB-File created
in mdb-path.

Acki
 
D

Dirk Goldgar

Joey said:
Hi All,

I am developing a stand alone application that synchronizes data from
a local MS Access97 DB with data from an MS Server DB elsewhere. I
would like to test to see if the Access DB is open or in use. Should
I have to parse the directory for the LDB file for the Access DB or
is there some more elegant way to achieve this? Many thanks in
advance.

Thanks,
Joey.

Are you talking about the database being open by another user, or by the
same user for whom this synchronizing application is running? If it's
another user you're worried about, one possibility would be to try to
open it exclusively, and see if that fails. Air code:

'----- start of "air code" -----
Dim db As DAO.Database

On Error Resume Next
Set db = DBEngine.OpenDatabase("C:\Path To\YourDB.mdb", True. True)
Select Case Err.Number
Case 0
' The database is not opened by anybody else.
db.Close ' Close it if we're not going to use it here.
Case 3356 ' I think; maybe others
' The database is opened by another user.
MsgBox "The database is currently open for another user."
Case Else
' Some other error has occurred.
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
End Select
'----- end of "air code" -----

However, if it's open by the same user, I don't think this will work.
 
J

Joey

Acki,

Thank you very much. It works beautifully.

Much appreciated,
Joey.

Jörg Ackermann said:
Hi,

Joey" <"jpk808[NO SPAM] schreibselte:
I am developing a stand alone application that synchronizes data from
a local MS Access97 DB with data from an MS Server DB elsewhere. I
would like to test to see if the Access DB is open or in use. Should
I have to parse the directory for the LDB file for the Access DB or
is there some more elegant way to achieve this? Many thanks in
advance.


I would use a function like this:

Public Function IsFileOpened(ByVal Pfad As String) As Boolean

Dim FileNr As Integer
Dim ErrNr As Long

On Error Resume Next
FileNr = FreeFile
Open Pfad For Input Lock Write As #FileNr
ErrNr = Err.Number
Close #FileNr
On Error GoTo 0

Select Case ErrNr
Case 0
IsFileOpened = False
Case 70
IsFileOpened = True
Case Else
Err.Raise ErrNr
End Select

End Function

Note:
If the MDB is opened exclusive, ther's no LDB-File created
in mdb-path.

Acki
 

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