ACC1x: How to Determine If Database Is Open Exclusively (1.x)ID: Q114837
|
This article describes a method using Access Basic that you can use to
determine if a database is open exclusively in Microsoft Access version
1.x.
This article assumes that you are familiar with Access Basic and with
creating Microsoft Access applications using the programming tools provided
with Microsoft Access. For more information on Access Basic, please refer
to the "Introduction to Programming" manual.
When a database is open exclusively, no other program or process can access
that database. When a database is open shared, other programs and processes
can get shared access to the database. This article demonstrates how to use
the Open statement in Access Basic to determine if a database is open
exclusively by using the Open statement's Shared argument to try to access
the database file in shared mode. If the database is open exclusively, an
error will occur. Trapping for the error determines whether the database is
open exclusively or not.
This function may be useful to Access Basic programmers who want to warn
their applications' users that a database is open in the wrong mode.
The following steps demonstrate how to determine whether a database is open
exclusively:
Option Explicit
Function IsCurDBExclusive1x () As Integer
' Purpose: Determine if a database is open exclusively.
' Returns: 0 if the database is not open exclusively.
' -1 if the database is open exclusively.
' Err if any error condition is detected.
Dim hFile As Integer
Dim DBName As String
hFile = FreeFile
'This is the name of the database to test.
dbname = "C:\access\nwind.mdb"
If Dir$(DBName) <> "" Then
On Error Resume Next
Open dbname For Binary Access Read Write Shared As hFile
Select Case Err
Case 0
IsCurDBExclusive1x = False
Case 70
IsCurDBExclusive1x = True
Case Else:
IsCurDBExclusive1x = Err
End Select
Close hFile
On Error GoTo 0
Else
MsgBox "Couldn't find " & dbname & "."
End If
End Function
Microsoft Access "Language Reference," version 1.x, pages 343-345
For more information about accomplishing the same task in later versions of
Microsoft Access, please see the following article in the Microsoft
Knowledge Base:
Q117539 ACC: How to Determine If Database Is Open Exclusively
Keywords : kbusage GnlMu
Version : 1.0 1.1
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 3, 1999