Locking individual records

D

Dale Fye

I'm attempting to use SharePoint 2007 lists as tables for an Access
application (long story). My understanding is that Sharepoint doesn't do a
very good job of handling record locking, so I thought I might try to
implement my own.

My concept was that I would lock each record, as it is displayed on the form
(OnCurrent event), so that no other user can edit, the record, while the user
that got to that record first has it displayed in his form. My intent was to
"unlock" each record when I move to the next record (regular navigation
buttons), or when I closed the form, but that segment of the code (in both
the Current and Close events of the form) is generating an error (Runtime
error #3218: Could not update; currently locked) when I try to implement the
Currentdb.execute line).

I added a field [IsLocked] to my table and to the forms Record Source, but
did not create a control to display that field. I also created a form level
public variable (lngID), which I use to keep track of the forms previous
record (if I locked that record).

I'm having a brain cramp this morning and cannot figure out why I am getting
any error, since at the point the error is occuring, I've already moved on to
another record.

I'm wondering whether I should use another event (what is the last form
level event that fires when leaving one record for another, using the
standard navigation buttons?) or try something else. Any ideas would be
appreciated.

Private Sub Form_Current()

Dim strSQL As String

'If I'm responsible for locking the previous record is locked, then
unlock it
If lngID <> 0 Then
strSQL = "UPDATE tbl_POCs SET [IsLocked] = 0 "
& "WHERE [ID] = " & lngID
CurrentDb.Execute strSQL, dbFailOnError
lngID = 0
End If

'If the current record is not locked, then lock it so no one
'else can edit it. Also, unlock the controls so that I can edit it.
'If the current record was locked by someone else, then
'display a message and lock the tagged text, cbo, and list controls
If Not Me.IsLocked Then
lngID = Me.ID
Me.IsLocked = True
Me.Dirty = False
Call ControlLock(Me, False)
Else
MsgBox "This record is currently locked by another user!"
Call ControlLock(Me, True)
End If

End Sub

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top