Results 1 to 2 of 2

Thread: Exclusively Lock Table

  1. #1

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Exclusively Lock Table

    I am trying to lock a table so that no one can edit it while its open.

    This is in VBA using MS Access 2002.
    I am opening my table as follows, as long as this table is open I want it locked.

    VB Code:
    1. 'Connect to recordset
    2.     Set Db = dbEngine.Workspaces(0)(0)
    3.     Set RstImport = Db.OpenRecordset("SELECT * FROM " & dbTable)


    And how do I check if the table is locked because if its locked I want to prompt the user "Hey this table is locked!"

    Thanks

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Exclusively Lock Table

    Depends how you are getting data to the screen. If via code you should get an error whilst attempting to open the recordset OR whilst trying to save the data change.
    Most people are trying not to get the tables locked so I'm not sure if there is a property on the recordset you open that says state=locked. ADO might have one, which you can check.

    Other alternative would be a field that says the record is locked by a user and time/date they did that. But you may need to use a clear query (Update) to reset those that are more than 12 hrs old for those users that forget to unlock/release the record(s).

    Another alternative is to hold the live record and have an audit trail of previous records data. The user can then see a history of all the changes, who did them and when...

    Edit:
    You can use error ignoring/handling
    Code:
    on error resume next
    
    set rst = db.openrecordset("sql statement")
    if err.number=0 then
    '---- no error
    else
    '---- error (locked?)
    end if
    Last edited by Ecniv; Feb 9th, 2006 at 04:21 AM.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

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



Click Here to Expand Forum to Full Width