lock a single field in ado recordset

Posted on 2004-11-03
Last Modified: 2013-12-25
Someone know if are possible to lock a single field in ado recordset?
Question by:francecap
    LVL 69

    Expert Comment

    by:Éric Moreau
    You cannot lock less then a row and very often a page (many rows) are locked.

    Author Comment

    with some expedient to code livel?

    Expert Comment

    Can you tell us what you are trying to achieve?

    Author Comment

    I want to lock recordset field ex:
    rst.fields(1) [locked]
    rst.fields(2) [not locked]
    the use of control binded to rst.fields(1) are not possible, like locked=true property of textbox Microsoft
    the use of control binded to rst.fields(2) are possible, like locked=false property of textbox Microsoft

    note that I have control non stadard Microsoft, that not has locked property!

    LVL 69

    Expert Comment

    by:Éric Moreau
    I think you are mixing 2 concepts:
    1. locking control on the screen
    2. locking fields in the database

    1. Which control is it? Do you have the Enabled property?
    2. This cannot be done on a field basis.
    LVL 3

    Expert Comment

    Here is what I would do, and it works with Access, and it should also with ADO.

    Create a query for your able, and to lock certain fields make them calculated field with an alias.  Example:

    SELECT EmailAddress, FromAddress & "" AS TheAddress FROM Table1

    You will be able to edit the EmailAddress field but not "TheAddress" field.

    Good luck.

    Chris Lewis
    LVL 69

    Expert Comment

    by:Éric Moreau
    >>You will be able to edit the EmailAddress field but not "TheAddress" field.

    The asker seems to want to lock it on screen. This method will only lock the database update, not the screen.

    Accepted Solution

    what control are you using here?

    it may have other properties like "controltype" that can be used.

    in any case you could put your control on top of a container like a picture box or a frame, you could disable that in code. That would have practically same effect.  you wont be able to click into control at all. only problem is if you wish to have copy to clipboard from that control.
    LVL 12

    Expert Comment

    It seems like you're using a "Page-Level" locking where two or more records are locked when a user invokes an Edit operation.
    Try this method (if using an Access Database). This should eliminate the problem.

     Dim oCN As ADODB.Connection

     Set oCN = New ADODB.Connection
     oCN.Provider = "Microsoft.JET.OLEDB.4.0"
     oCN.Properties("Data Source") = "C:\Temp\MyDB.mdb"
     oCN.Properties("Jet OLEDB:Database Locking Mode") = 1      '<-- This enforces a "Record-Level" locking
     oCN.CursorLocation = adUseServer

    Expert Comment

    Glad to be of assistance

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Automated script task to send email 22 83
    Macro which simplifies accounts 6 49
    Extract Data and filename Macro 20 90
    Adding to a VBA? 6 31
    Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now