Why getting "You dont have exclusive access to the db at this time

G

Gary S

I have a form that has a timer set and runs the following code:

Public Sub ExpiredDatabase()
Dim WrkJet As Workspace
Dim db As Database
Dim Rst As Recordset
Dim ExpiredMdb1 As String
Dim ExpiredMdb2 As String

On Error GoTo ErrorHandler:

ExpiredMdb1 = "J:\USERS\DEPT\FINRPT\ExpiredDatabases\ExpiredDatabases.mdb"
ExpiredMdb2 = "J:\FINRPT\ExpiredDatabases\ExpiredDatabases.mdb"

Set WrkJet = CreateWorkspace("", "admin", "", dbUseJet)

If HowAreTheyMapped = "j:\users" Then
Set db = WrkJet.OpenDatabase(ExpiredMdb1, False)
Else
Set db = WrkJet.OpenDatabase(ExpiredMdb2, False)
End If

Set Rst = db.OpenRecordset("ExpiredDatabasesTbl")

Rst.MoveFirst
Do While Not Rst.EOF
If Rst("MdbPathFileName") = CurrentDbPathName Then
Rst.Close
Set Rst = Nothing
Set db = Nothing
WrkJet.Close
Set WrkJet = Nothing
'MsgBox "The database you are using has expired."
DoCmd.OpenForm "testfrm"
Exit Sub
End If
Rst.MoveNext

Loop

Rst.Close
Set Rst = Nothing
Set db = Nothing
WrkJet.Close
Set WrkJet = Nothing
Exit Sub

ErrorHandler:
Rst.Close
Set Rst = Nothing
Set db = Nothing
WrkJet.Close
Set WrkJet = Nothing
MsgBox Err.Description

End Sub

Public Function CurrentDbPathName() As String
Dim db1 As Database
Set db1 = CurrentDb
CurrentDbPathName = db1.Name
Set db1 = Nothing
End Function

Public Function HowAreTheyMapped() As String
HowAreTheyMapped = Left(CurrentDbPathName(), 8)
End Function


When I this code with message box everything is fine.

But when I run it and it opens the form instead,
I get the message:
"You do not have exclusive access to the database at this time"
First of all, no one else is in the database.

Why am I getting this message when I only went from
a message box to form delivering the message.

Thanks so much for any help!!!!!

Gary S
 

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