Change a Record to Read Only

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • plaguna
    New Member
    • May 2008
    • 58

    Change a Record to Read Only

    How can I change a record to Read Only? I have a Database (MS Access 2007) in a public folder, which many people have access to it and, we have no control over some of them to make unnecessary changes to fields or records. I was reading about setting the “Allow Edits” Property to False from a Form to avoid changes, but but I can’t find a way how to do it. Can anyone tell me if this is the best options and/or what the steps would be?
    Any help is greatly appreciated.
    Thank you in advance

    plaguna
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    Setting the Allow Edits property is a fine way to lock the record. Note that "Changing a field value programmaticall y causes the current record to be editable, regardless of the AllowEdits property setting." from this reference. I would suggest reading all of that page anyway.

    To find this property:
    • Open the form in design view
    • Open the Property Sheet
    • Make sure that "Form" is selected in the drop-down at the top of the Property Sheet
    • Select the Data tab
    • You will see Allow Edits toward the bottom of the list

    If you don't have too many controls to worry about, or you only want to lock individual controls, you can set their Locked and/or Enabled properties for the same effect.

    Comment

    • plaguna
      New Member
      • May 2008
      • 58

      #3
      Great information. Thank you.
      Therefore, When I set the AllowEdits property to “No” It sets to all records of the Form, and my intension is to AllowEdits=No to only a specific Record. Also, I Added this code to the On Current event of my Form in order to set the AllowEdits Property based on the contents of the CompletionDate field in my form:
      Private Sub Form_Current()
      Me.AllowEdits = IsNull(Me.Compl etionDate)
      End Sub
      That way if the field has a value, then set the AllowEdits property to false.
      My problem is that even if this makes sense, It doesn’t work. No matter what I code to the On Current event of my form, If the AllowEdits property is set to NO, It always sets to all records and not to what I am trying to do; “AllowEdit s Property to false to only one record”.
      Thank you in advance for helping,

      Plaguna

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        If the AllowEdits property is set to NO
        Are you saying that you have AllowEdits set to No in the Properties sheet? It shouldn't be. With it set to Yes in the form's Properties and your code in place, it should work exactly as you want.

        Linq ;0)>

        Comment

        • ChipR
          Recognized Expert Top Contributor
          • Jul 2008
          • 1289

          #5
          I put some code in a command button and used it to toggle the AllowEdits property. I found that toggling the property from True to False did not prevent me from editing the record. Until the reason for this is found, you can set all the individual controls to locked or unlocked.

          Comment

          • OldBirdman
            Contributor
            • Mar 2007
            • 675

            #6
            I did a similar test to ChipR, only I toggled in the OnCurrent event, testing one field to determine True or False. Neither condition prevented me from editing the selected record, and saving it. Access 2000 and Access 2002.

            Comment

            • FishVal
              Recognized Expert Specialist
              • Jun 2007
              • 2656

              #7
              Code:
              Private Sub Form_Current()
                  With Me
                      .AllowEdits = (.key1 = 2)
                  End With
              End Sub
              works as expected in Access 2003.
              [key1] is a textbox

              Comment

              • plaguna
                New Member
                • May 2008
                • 58

                #8
                Please Tell me if I’m doing something wrong, because no matter what the code in the On Current event is, I’m still allowed to edit.
                These are the steps:
                1. Open the form with the record I want to lock
                2. Change to Dedign view
                3. Set the AllowEdits property on the form to Yes. (from Property Sheet, Data tab)
                4. Set the On Current property (Event tab) of the form to the following event procedure:

                Code:
                Private Sub Form_Current()
                    Me.AllowEdits = IsNull(Me.CompletionDate)
                End Sub
                5. Save the form and open it in Form view.

                Also, I changed the code to test if I’m allowed code to run and, there is no indication of code execution.

                Code:
                Private Sub Form_Current()
                    MsgBox "Can you hear me now?"
                    Me.AllowEdits = IsNull(Me.CompletionDate)
                End Sub
                Is there a possibility for my Access 2007 not to allow code execution? I that would be the case, is there a way to enable it?

                Thank you for your help

                plaguna

                Comment

                • FishVal
                  Recognized Expert Specialist
                  • Jun 2007
                  • 2656

                  #9
                  Originally posted by plaguna
                  ...
                  Is there a possibility for my Access 2007 not to allow code execution? I that would be the case, is there a way to enable it?
                  ...

                  Comment

                  • plaguna
                    New Member
                    • May 2008
                    • 58

                    #10
                    Good site but, it is not exactly what I am looking for. Thank you anyway.
                    plaguna

                    Comment

                    Working...