none
Need to lock the entire table and prevent users from editing RRS feed

  • Question

  • Hi there,

    We are working with accessing MS access database. We need to lock the entire table and prevent tables from editing. I have checked with "table.Properties["ReadOnly"].value=true" and "field.Properties["ReadOnly"].value=true", but neither of them is working. Is there any way to do this? Please help.

    Regards,
    Shiva

    Tuesday, February 2, 2016 1:11 PM

All replies

  • You can't lock a table. Instead

    a) Make sure that the end user cannot edit data directly in a table or query, by hiding the navigation pane and disabling the Access special keys.

    b) Provide a form that lets users view but not edit the data, by setting the Recordset Type property of the form to Snapshot. And/or provide a report to view the data.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Tuesday, February 2, 2016 3:14 PM
  • We are working with accessing MS access database. We need to lock the entire table and prevent tables from editing. I have checked with "table.Properties["ReadOnly"].value=true" and "field.Properties["ReadOnly"].value=true", but neither of them is working. Is there any way to do this? Please help.

    Under what circumstances do you want to lock the table?  Do you need to lock it for a short time, while you carry out some operation, or do you need the table to be read-only for all users, in all circumstances?

    If you need to lock it only for a short time, you can open a recordset on the table with appropriate options to deny access to other users:  dbDenyRead + dbDenyWrite.

    If you need to the table to be read-only for all users, at least in all normal circumstances, you could put the table in a separate database file, set the Windows "read-only" attribute of that database file, and link to that table from the application database your users will be using.  Note, though, that doing it that way will prevent you from enforcing referential integrity on any relationships between that table and other table that are local to the application database.

    From your code quotes, it looks like you are not using Access itself, and VBA, to work with the database.  If that's so, it would be helpful if you gave more background to what you are trying to do and where this table fits in.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Tuesday, February 2, 2016 4:00 PM
  • Hi,

    Thanks for your update.

    We need to lock the table for all the users..i.e make the tables readonly..It would be okay if we are able to make certain columns alone readonly.. FYI, we are using C# for accessing MS Access. I am looking for a code for doing that. Please help.

    Regards,

    Shiva




    • Edited by ShivaBalaji Thursday, February 4, 2016 3:00 PM
    Thursday, February 4, 2016 6:18 AM
  • We need to lock the table for all the users..i.e make the tables readonly..It would be okay if we are able to make certain columns alone readonly.. FYI, we are using C# for accessing MS Access. I am looking for a code for doing that. Please help.

    I'm sorry, but I still need clarification.  Are you talking about locking the table for *Access* users; that is, people who are using Microsoft Access to open and work with the database?  Or is it only users of your C# application that you are concerned about?

    If it's Access users you are concerned about, then I think my earlier suggestion of placing the table in a separate, read-only database file, and linking to that table from the application database would serve. 

    That would probably work for your C# application as well, but I would think that in C# you ought to be able to manipulate the Connection property of whatever object is actually opening the table in such a way that it is opened read-only.  However, I haven't had occasion to do that, so I'd have to read up on the subject.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Thursday, February 4, 2016 3:24 PM
  • Hi There,

    As I said in my previous update, we are using c# code for accessing MS Access application. We need to make the MS access columns as readonly from C# codes. Is there any code for this? Please help

    Regards,

    Shiva

    Tuesday, February 9, 2016 10:10 AM
  • If my previous suggestion doesn't apply, I don't think I can help you without answers to the questions I asked before.  I'm still not sure I understand you, because what your asking doesn't make sense to me.

    It does occur to me that, in any given query, you can make certain columns read-only by defining them as calculated fields, created by wrapping them in a function that returns the original value of the field.  For example, in a query you could make Field2 uneditable by writing:

        SELECT MyTable.Field1, MyTable.Field2 & '' As Field2 FROM MyTable

    If in a C# application you were to bind some object to a query like this, then for that object, the Field2 column would be uneditable.

    However, I don't know if this is the sort of thing you're looking for.  If it isn't, then in order to provide other advice I would have to have a much more complete, detailed understanding of your setup and what you are trying to do.  So far, you haven't given me that.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Wednesday, February 10, 2016 5:41 PM
  • You need to explain how your C# application is interfacing with MS Access.
    Wednesday, February 10, 2016 7:54 PM
  • ENTER VALIDATION RULE IN TABLE PROPERTIES (NOT UNDER DESIGN PANE) AS FALSE
    Friday, July 20, 2018 8:57 AM
  • Why you don't split backend (Contain your table) and frontend. then i set password for backend. No one can edit your table
    Friday, July 20, 2018 3:15 PM