How to lock a field in a record or make it read only in Access 2007

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sweetfalguni
    New Member
    • Oct 2009
    • 4

    How to lock a field in a record or make it read only in Access 2007

    Hello,

    The codes below worked successfully in Access 2003
    Code:
    Private Sub Form_Current()
      If Me.NewRecord Then
        Me.AllowAdditions = True
        Me.AllowDeletions = True
        Me.AllowEdits = True
    Else
        Me.AllowAdditions = True
        Me.AllowDeletions = False
        Me.AllowEdits = False
    End If
    and
    Code:
    Sub cmdEdit_Click 
    On Error GoTo Err_cmdEdit_Click 
      
       Me.AllowEdits = True 
      
    Exit_cmdEdit_Click: 
        Exit Sub 
      
    Err_cmdEdit_Click: 
        MsgBox Err.Description 
        Resume Exit_cmdEdit_Click 
      
    End sub
    It works successfully in Access 2003 but it doesnt work in Access 2007. Please help
    Last edited by NeoPa; Oct 26 '09, 01:27 PM. Reason: Please use the [CODE] tags provided.
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    I think I remember having a problem with this. I ended up locking/disabling each of the relevant controls.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      Can you please expand on :
      Originally posted by sweetfalguni
      It works successfully in Access 2003 but it doesnt work in Access 2007.
      Does it give an error message?
      If so what?
      Which line does it fail on?

      Comment

      • Megalog
        Recognized Expert Contributor
        • Sep 2007
        • 378

        #4
        If this has been converted to a Split Form after your 2007 upgrade, it may not work.
        You'll have to replace the "Me." with "[Forms]![formname]."

        If not, then... I'm not sure =)

        Comment

        • ChipR
          Recognized Expert Top Contributor
          • Jul 2008
          • 1289

          #5
          In my experience, there was no error message. AllowEdits = False just seems to have no effect.

          Comment

          Working...