This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.
NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access version 2.0. For more information about Access Basic, please refer to the "Building Applications" manual.
The following sample function demonstrates how to use the Open statement to determine in what mode the current database is open. This function is most useful to programmers who want to warn users that the database being opened is in the incorrect mode:
- Open the sample database Northwind.mdb (or NWIND.MDB in version 2.0) exclusively.
- Create a module and type the following line in the Declarations section if it is not already there:Option Explicit
- Type the following procedure:
Function IsCurDBExclusive () As Integer
' Purpose: Determine if the current database is open exclusively.
' Returns: 0 if database is not open exclusively.
' -1 if database is open exclusively.
' Err if any error condition is detected.
Dim db As Database
Dim hFile As Integer
hFile = FreeFile
Set db = dbengine.workspaces(0).databases(0)
If Dir$(db.name) <> "" Then
On Error Resume Next
Open db.name For Binary Access Read Write Shared As hFile
Select Case Err
IsCurDBExclusive = False
IsCurDBExclusive = True
IsCurDBExclusive = Err
On Error GoTo 0
MsgBox "Couldn't find " & db.name & "."
- To test this function, type the following line in the Debug window (or the Immediate window in version 2.0), and then press ENTER:If IsCurDBExclusive()=True Then Msgbox "It's Exclusive!"Note that you receive the message, "It's Exclusive!".
- Open the database not exclusively, and then repeat step 4. Note that the message does not appear.
ID članka: 117539 – Zadnji pregled: 18. jan. 2007 – Revizija: 1