P
Pat Hall
I've picked up support for an Access 2002 database. Having problem with some
VBA code since I am learning VBA as I go.
When I run the code I get the message "Could not update; currently locked by
another session on this machine."
The message is happening on the .Edit statement.
There are no other sessions on this machine. The database links to Access
tables in another database.
I looked on the internet but was unable to find a suggestion that helps me.
The code is below. The part between the lines is where the problem is. The
code above and below the lines works correctly.
Private Sub Update_New_Address_Click()
On Error GoTo Err_Update_New_Address_Click
Dim db As Database
Dim sqlHouse, sqlASteps As String
Dim rsHouse, rsASteps, rsAStepsOpen As Recordset
Dim cnt As Integer
'Make sure New Address is filled in
If IsNull(CANewAddress) Then
MsgBox "You need to fill in the New Address field"
Exit Sub
End If
'Check for Duplicate address
cnt = DCount("[Address]", "tblActionSteps", "[Address]='" & CANewAddress
& "'")
If cnt > 0 Then
MsgBox " This address already exists in the database."
Exit Sub
End If
'Tested OK to here
____________________________________________________________________
Set db = CurrentDb
'Update tblHouse
Set rsHouse = db.OpenRecordset("tblHouse", dbOpenDynaset)
With rsHouse
.FindFirst "Address = '" & Me!Address & "'"
If Not .NoMatch Then 'record found
.Edit
!Address = Me!CANewAddress
.Update
End If
End With
____________________________________________________________________
'Update tblActionSteps
' Tested OK below here
Set rsAStepsOpen = db.OpenRecordset("tblActionSteps", dbOpenDynaset)
Set rsASteps = db.OpenRecordset("Select * From tblActionSteps Where
Address = '" & Me!Address & "'")
Do While Not rsASteps.EOF
rsASteps.Edit
rsASteps!Address = Me!CANewAddress
rsASteps.Update
rsASteps.MoveNext
Loop
'Cleanup
rsASteps.Close
rsAStepsOpen.Close
rsHouse.Close
Set db = Nothing
DoCmd.Close
Exit_Update_New_Address_Click:
Exit Sub
Err_Update_New_Address_Click:
MsgBox Err.Description
Resume Exit_Update_New_Address_Click
End Sub
VBA code since I am learning VBA as I go.
When I run the code I get the message "Could not update; currently locked by
another session on this machine."
The message is happening on the .Edit statement.
There are no other sessions on this machine. The database links to Access
tables in another database.
I looked on the internet but was unable to find a suggestion that helps me.
The code is below. The part between the lines is where the problem is. The
code above and below the lines works correctly.
Private Sub Update_New_Address_Click()
On Error GoTo Err_Update_New_Address_Click
Dim db As Database
Dim sqlHouse, sqlASteps As String
Dim rsHouse, rsASteps, rsAStepsOpen As Recordset
Dim cnt As Integer
'Make sure New Address is filled in
If IsNull(CANewAddress) Then
MsgBox "You need to fill in the New Address field"
Exit Sub
End If
'Check for Duplicate address
cnt = DCount("[Address]", "tblActionSteps", "[Address]='" & CANewAddress
& "'")
If cnt > 0 Then
MsgBox " This address already exists in the database."
Exit Sub
End If
'Tested OK to here
____________________________________________________________________
Set db = CurrentDb
'Update tblHouse
Set rsHouse = db.OpenRecordset("tblHouse", dbOpenDynaset)
With rsHouse
.FindFirst "Address = '" & Me!Address & "'"
If Not .NoMatch Then 'record found
.Edit
!Address = Me!CANewAddress
.Update
End If
End With
____________________________________________________________________
'Update tblActionSteps
' Tested OK below here
Set rsAStepsOpen = db.OpenRecordset("tblActionSteps", dbOpenDynaset)
Set rsASteps = db.OpenRecordset("Select * From tblActionSteps Where
Address = '" & Me!Address & "'")
Do While Not rsASteps.EOF
rsASteps.Edit
rsASteps!Address = Me!CANewAddress
rsASteps.Update
rsASteps.MoveNext
Loop
'Cleanup
rsASteps.Close
rsAStepsOpen.Close
rsHouse.Close
Set db = Nothing
DoCmd.Close
Exit_Update_New_Address_Click:
Exit Sub
Err_Update_New_Address_Click:
MsgBox Err.Description
Resume Exit_Update_New_Address_Click
End Sub