Results 1 to 3 of 3

Thread: Record Locking

  1. #1
    Join Date
    Dec 2009
    Location
    Antwerp (Belgium)
    Posts
    33

    Unanswered: Record Locking

    Why don't I get an error in the immediate window when I do the following ?

    Code:
    set ors = currentdb.OpenRecordset("artikel",,dbPessimistic)
    set ors1 = currentdb.OpenRecordset("artikel",,dbPessimistic)
    ors.edit
    ors1.edit
    I was hoping that the second edit would throw an error, so that I could,through error trapping, use this for my recordlocking purposes. I need to prevent people two people to open the same record concurrently.

    How is that handled then, apart for the obvious solution to have a "locked" table in the database?

    Thanks.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    According to the Access documentation, the lockedits argument must be the fourth argument, not the third one :
    Code:
    Set recordset = object.OpenRecordset (source, type, options, lockedits)
    This argument is only valid with certain types and certain options.

    As dbPessimistic has a numeric value of 2, using it as the third argument is the same as using dbDenyRead that also has a numeric value of 2. In reality, your instruction is interpreted as:
    Code:
    set ors1 = currentdb.OpenRecordset("artikel",, dbDenyRead)
    Moreover, when dbPessimistic is used, the page containing the row you edit is locked, not the whole dataset.
    Have a nice day!

  3. #3
    Join Date
    Dec 2009
    Location
    Antwerp (Belgium)
    Posts
    33

    Red face

    You're absolutely right, and I am truly sorry.

    So I went back to the doc, but I must say I'm still not convinced I understand this (in fact I am convinced that I don't understand this ) .

    Here's a routine that runs from the immediate window without any runtime error, where I would have expected that when ors1 executes it's edit, the code would throw an error. To be complete, please note that "ARtikel" is a linked table.

    Code:
    Sub test2()
    Dim ors As DAO.Recordset, ors1 As DAO.Recordset
    Set ors = CurrentDb.OpenRecordset("Artikel", dbOpenDynaset, dbConsistent, dbPessimistic)
    Set ors1 = CurrentDb.OpenRecordset("Artikel", dbOpenDynaset, dbConsistent, dbPessimistic)
    ors.MoveFirst
    ors.Edit
    ors1.MoveFirst
    ors1.Edit 'expecting a run time error
    ors.Update
    ors1.Update
    Set ors = Nothing
    Set ors1 = Nothing
    End Sub
    Last edited by Marc Grajower; 12-27-09 at 15:15.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •