I have a form with a button that when clicked should perform the following action on the current DB;
Open table TEMP and allow reading of the TEMP's "Sector" field to be stored in a variable for later comparison and update. Before I could even start coding the logic, I am getting the following error from access:
"The database has been placed in a state by user that prevents it from being opend or locked."
Here is my code (FYI: logic portion not complete yet):
Private Sub Command0_Click()
Dim myConnection As ADODB.Connection
Dim myRecordset As ADODB.Recordset
Dim pathstring As String
Dim str As String
Set myConnection = New ADODB.Connection
Set myRecordset = New ADODB.Recordset
pathstring = Application.CurrentProject.FullName
str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & pathstring & ";Persist Security Info=False"
myConnection.ConnectionString = str
'-Open the Connection --
myConnection.Open
'Determine if we conected.
If myConnection.State = adStateOpen Then
myRecordset.Open "Select * From TEMP", myConnection, adOpenDynamic, adLockOptimistic, adCmdText
Else
MsgBox "The connection could not be made."
myConnection.Close
Exit Sub
End If
'-just to be sure --
myRecordset.MoveFirst
On Error GoTo transError
'-here is the top of the transaction--
myConnection.BeginTrans
While Not myRecordset.EOF
mcounter = mcounter + 1
myRecordset!Sector = "5"
myRecordset.Update
myRecordset.MoveNext
Wend
myConnection.Close
myRecordset.Close
myConnection.Close
Exit Sub
transError:
myConnection.RollbackTrans
myRecordset.Close
myConnection.Close
MsgBox Err.Description
End Sub