Hi. I've only posted here a couple times, and it was quite a while ago. So if i need to post in another section or have any other errors in my post, apologies...just lmk and i will correct it.
Access: 365 Enterprise (version 2108 (Build 14326.20600))
OS: Windows 10
Error 3260 = Could not update; currently locked by user 'blah blah' on machine 'blah blah'
I'm pretty sure i know why it's happening. We have an import procedure that can take a while to run. The db is pulling the data from mainframe screens. The following sounds kind of wonky, but i don't have access to mainframe tables (this is a judiciary application and the tables are pretty locked down)...so this is my only option...
The vba manipulates the mainframe...simulating keystrokes (F1, F2, Enter, etc.) to "push" it from one screen to another. It "scrapes" the info from the mainframe screens as it goes, then creates a record in the db. The procedure is looping through and adding 10-80 records and can take a few min to run depending on the amount of records.
We ran into the 3260 error when more than one person was importing at the same time. It's a rare occurrence (the import procedure is only run sporadically), but it can happen. They're importing and adding different records, but i think the collision is happening due to the primary key.
The code creates a new record, which assigns it a new autonumber for the primary key (i believe this happens before committing the record). The other user's import is also creating new records (same table), and so also creates autonumbers. I think the vba is creating new records very close together in time for each user...however one commits the record before the other (or i guess sometimes the commit tries to happen at the same time), and thus attempts to commit record with same primary key. One of the users also got the "this will create duplicate key entries" error as we tested, so i think my assumption may be correct. Hopefully this all makes sense.
Code:
'--Next create and populate the Def Hearing record (or EDIT it if it already exists)
If CaseAlreadyExists = True Then
strWhere = "[DefHearingID] = " & DefHearingID
strSql = "Select * from [tblDefHearings] where " & strWhere
Set rsDefHearings = CurrentDb.OpenRecordset(strSql, dbOpenDynaset)
rsDefHearings.MoveFirst
rsDefHearings.Edit
'--NOTE: No one would be editing the same record that already exists at the same time...it's the below (adding new records) that's causing the issue
ElseIf CaseAlreadyExists = False Then
strSql = "Select * from [tblDefHearings]"
Set rsDefHearings = CurrentDb.OpenRecordset(strSql, dbOpenDynaset)
rsDefHearings.AddNew
End If
'--Now that we are in ADD record or EDIT record "mode", go ahead and populate the fields.
With rsDefHearings
.Fields("JailIndicator") = JailIndicator
....more fields are added in this spot before updating
.Update '--this is where the procedure borks out
End With
Set rsDefHearings = Nothing
Is there maybe a way to maybe roll back the record creation if i trap this error, and then attempt to create a new record again which would assign a new (and hopefully different) primary key??
Any assistance is very much appreciated!
Thanks!