Database in a state that prevents it from being opened or locked

L

Lynn Trapp

Hi everyone,

I've encountered an odd situation running some VBA Code in A2007. It will
run fine when I first open the database and through subsequent iterations,
until I modify the code and compile it. That's when the following error is
encountered. If I close the database and rerun the code, it works fine, until
another change is made. Any thoughts or suggestions?

The error message is: "The database has been put in a state by user 'Admin'
on Machine <machine name> that prevents it from being opened or locked."

The code is:

Public Sub UseTransactions()
'Define the Variables
Dim cn As New ADODB.Connection
Dim strSQL As String
Dim strSQL2 As String

strSQL = "UPDATE Customers SET Customers.City = ""Washington"" WHERE
(((Customers.CustomerID)=6));"
'strSQL2 = "INSERT INTO tblInvoice ( InvoiceNo, InvoiceDate, CustomerID,
Comments ) VALUES (5,#1/26/2010#,5,""Invoice for Customer 5"");"


'Open the connection to the current database
With cn
.ConnectionString = CurrentProject.Connection
.Open
End With

'Set error handling
On Error GoTo Transaction_Err:

'Try to complete a transaction. If an error occurs,
'the error handling routine will rollback
cn.BeginTrans
cn.Execute strSQL
'cn.Execute strSQL2
cn.CommitTrans

Transaction_Exit:

'Clean up
cn.Close
Set cn = Nothing
Exit Sub

Transaction_Err:

'an error occurrec, rollback the transaction
MsgBox Err.Number & "-" & Err.Description
cn.RollbackTrans
Resume Transaction_Exit

End Sub
 

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