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.Connectio n
Dim myRecordset As ADODB.Recordset
Dim pathstring As String
Dim str As String
Set myConnection = New ADODB.Connectio n
Set myRecordset = New ADODB.Recordset
pathstring = Application.Cur rentProject.Ful lName
str = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source= " & pathstring & ";Persist Security Info=False"
myConnection.Co nnectionString = str
'-Open the Connection --
myConnection.Op en
'Determine if we conected.
If myConnection.St ate = adStateOpen Then
myRecordset.Ope n "Select * From TEMP", myConnection, adOpenDynamic, adLockOptimisti c, adCmdText
Else
MsgBox "The connection could not be made."
myConnection.Cl ose
Exit Sub
End If
'-just to be sure --
myRecordset.Mov eFirst
On Error GoTo transError
'-here is the top of the transaction--
myConnection.Be ginTrans
While Not myRecordset.EOF
mcounter = mcounter + 1
myRecordset!Sec tor = "5"
myRecordset.Upd ate
myRecordset.Mov eNext
Wend
myConnection.Cl ose
myRecordset.Clo se
myConnection.Cl ose
Exit Sub
transError:
myConnection.Ro llbackTrans
myRecordset.Clo se
myConnection.Cl ose
MsgBox Err.Description
End Sub
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.Connectio n
Dim myRecordset As ADODB.Recordset
Dim pathstring As String
Dim str As String
Set myConnection = New ADODB.Connectio n
Set myRecordset = New ADODB.Recordset
pathstring = Application.Cur rentProject.Ful lName
str = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source= " & pathstring & ";Persist Security Info=False"
myConnection.Co nnectionString = str
'-Open the Connection --
myConnection.Op en
'Determine if we conected.
If myConnection.St ate = adStateOpen Then
myRecordset.Ope n "Select * From TEMP", myConnection, adOpenDynamic, adLockOptimisti c, adCmdText
Else
MsgBox "The connection could not be made."
myConnection.Cl ose
Exit Sub
End If
'-just to be sure --
myRecordset.Mov eFirst
On Error GoTo transError
'-here is the top of the transaction--
myConnection.Be ginTrans
While Not myRecordset.EOF
mcounter = mcounter + 1
myRecordset!Sec tor = "5"
myRecordset.Upd ate
myRecordset.Mov eNext
Wend
myConnection.Cl ose
myRecordset.Clo se
myConnection.Cl ose
Exit Sub
transError:
myConnection.Ro llbackTrans
myRecordset.Clo se
myConnection.Cl ose
MsgBox Err.Description
End Sub
Comment