PDA

View Full Version : VBA Opening the Database in Shared Mode



brorick
11-16-2006, 01:11 PM
Does anyone know any vba code that would force an open database into shared mode so that I can prevent users from opening the database exclusively?

I did find the following code on the Microsoft website but I am not sure where it would go. :wot Any help is appreciated. Thank you.

Sub OpenDBShared (strDBPath As String)
Dim cnnDB As ADODB.Connection
Dim errCurrent As ADODB.Error
' Initialize Connection object
Set cnnDB = New ADODB.Connection
' Specify Microsoft Jet 4.0 provider and then try to open
' the database specified in the strDBPath variable in shared
' mode.
On Error Resume Next
With cnnDB
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Mode = adModeShareDenyNone
.Open strDBPath
End With
If Err <> 0 Then
' If errors occur, display them.
For Each errCurrent In ADODB.Errors
Debug.Print "Error " & errCurrent.SQLState _
& ": " & errCurrent.Description
Next
Else
' No errors: You have shared access.
Debug.Print "The database is open in shared mode."
End If
' Close Connection object and destroy object variable.
cnnDB.close
Set cnnDB = Nothing
End Sub

OBP
11-16-2006, 03:18 PM
Why use VBA why not secure the database?