PC Review


Reply
Thread Tools Rate Thread

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

 
 
Lynn Trapp
Guest
Posts: n/a
 
      27th Jan 2010
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

--
Lynn Trapp
MCP, MOS, MCAS
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: database gets placed in a State that prevents it from being opened JohnFol Microsoft Access Queries 0 14th Apr 2005 03:28 PM
The database has been placed in a state by user 'admin' on machine '1280-DEV1' that prevents it from being opened or locked. Dan D Microsoft Access 1 3rd Dec 2004 01:02 AM
Placed in a state that prevents db from being opened Microsoft Access 2 14th Apr 2004 10:24 PM
database was put in a state that prevents it from being open kay Microsoft Access 0 26th Aug 2003 04:36 PM
prevents it from being opened or locked Greg Youdale Microsoft Access 1 2nd Jul 2003 07:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:49 AM.