Hi,
I have a form for users to enter data and save it to table. Before saving, it should check if the record for the same ID & year already exist. If it is then just edit record. I got problem with this part. The msg I got is : "Could not update; currently locked by another session on this machine." Please help me to fix it. Thanks.
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT * FROM myTable WHERE ID = " & Chr(34) & Me![txtID] & Chr(34) & _
" AND Year = " & Chr(34) & Me![txtYear] & Chr(34)
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
With rs
If .BOF And .EOF Then
Me.AllowEdits = True
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Else
rs.Edit
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
'MsgBox "The record entered is already exist."
rs.Close
Set rs = Nothing
Exit Sub
End If
End With
rs.Close
Set rs = Nothing
I have a form for users to enter data and save it to table. Before saving, it should check if the record for the same ID & year already exist. If it is then just edit record. I got problem with this part. The msg I got is : "Could not update; currently locked by another session on this machine." Please help me to fix it. Thanks.
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT * FROM myTable WHERE ID = " & Chr(34) & Me![txtID] & Chr(34) & _
" AND Year = " & Chr(34) & Me![txtYear] & Chr(34)
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
With rs
If .BOF And .EOF Then
Me.AllowEdits = True
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Else
rs.Edit
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
'MsgBox "The record entered is already exist."
rs.Close
Set rs = Nothing
Exit Sub
End If
End With
rs.Close
Set rs = Nothing