I have a db that I use as a datawarehouse. Every day, I dump all the data from the tables and reload it with current data from our legacy system. This gives users great access to customer and product data that they would otherwise have to hand key.
The users link those tables into their own databases, or sometimes run queries directly in the datawarehouse and export the results.
The problem I'm having is that once in a while a user will open the db with Open Exclusive.
Not only does this lock everyone out of the database, it locks up all databases linked to it.
My solution (because I don't want to go through the hassle of using security for it), was to
have a hidden form open on startup with code like this in the OnOpen event (granted, the code's not pretty yet, but it should be functional):
Code:
Private Sub Form_Open(Cancel As Integer)
If IsDBOpenedExclusive(CurrentDb.Name) = True Then
msgbox "Please do not open this db in exclusive mode"
application.quit
End If
End Sub
Function IsExclusive(strDbName As String) As Boolean
'try to open the db again to see if we raise an error
On Error Resume Next
DBEngine.opendatabase (stDbName)
' If the database failed with error 3045,
' it was opened exclusively by someone else
' or possibly by ourselves.
IsDBOpenedExclusive = (Err.Number = 3045)
End Function
Unfortunately, if I open the database exclusively, the above code fires, but doesn't throw an error.
Any idea what could be wrong? Is there another method I should use?