Share via

MS Access - locking fields in a record

Anonymous
2010-06-04T00:31:35+00:00

I have a form that displays records, in one field in the record, if it is clicked, i would like to lock the other fields in that record only. How do you do this?

I've put code in, however it locks those fields for every record... I only want it to affect the record that has that check box clicked.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2010-06-04T23:12:07+00:00

You need to use much the same code for the form's current event procedure as you are presently using for the control's Click event procedure.  But you don't need to assign a Null to the control in this case, so:

If [Required].Value = True Then

    Me.Log.Locked = True

    Me.Log2.Locked = True

    Me.Log3.Locked = True

    Me.Log4.Locked = True

    Me.Log5.Locked = True

    Else

    Me.Log.Locked = False

    Me.Log2.Locked = False

    Me.Log3.Locked = False

    Me.Log4.Locked = False

End If

Is Log5 deliberately excluded from the latter set?  If so including it in the former will keep it locked once it is locked.

In the case of your current code, though, which you also need, I'd use the control's AfterUpdate event procedure rather than its Click event procedure.


Ken Sheridan, Stafford, England

Was this answer helpful?

0 comments No comments

7 additional answers

Sort by: Most helpful
  1. ScottGem 68,830 Reputation points Volunteer Moderator
    2010-06-04T20:24:01+00:00

    Are you using a form in continuous form mode?


    Hope this helps, Scott<> P.S. Please post a response to let us know whether our answer helped or not. Microsoft Access MVP 2009 Author: Microsoft Office Access 2007 VBA Technical Editor for: Special Edition Using Microsoft Access 2007 and Access 2007 Forms, Reports and Queries

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-06-04T15:35:14+00:00

    This is my code: It placed on the Click() of the check box that signals when the other fields get locked or not. 

    Right now when the button is clicked, it locks the fields for every record......

    Private Sub Required_Click()

    If [Required].Value = True Then

        Me.Log.Value = Null

        Me.Log.Locked = True

        Me.Log2.Value = Null

        Me.Log2.Locked = True

        Me.Log3.Value = Null

        Me.Log3.Locked = True

        Me.Log4.Locked = True

        Me.Log5.Value = Null

        Me.Log5.Locked = True

        Else

        Me.Log.Locked = False

        Me.Log2.Locked = False

        Me.Log3.Locked = False

        Me.Log4.Locked = False

    End If

    End Sub

    I tried putting code (below) to unlock them in the Form_current as you suggested, however it just overrode the above code and allows me to edit all the fields.

        Me.Log.Locked = False

        Me.Log2.Locked = False

        Me.Log3.Locked = False

        Me.Log4.Locked = False

        Me.Log5.Locked = False

    am I putting the code in the right spot? is this the correct code?

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-06-04T02:03:24+00:00

    Use the Current event to test the value and unlock as necessary.

    --

    Arvin Meyer, MCP, MVP

    http://www.datastrat.com

    http://www.accessmvp.com

    http://www.mvps.org/access

    Co-author: "Access 2010 Solutions", published by Wiley


    Arvin Meyer MCP, MVP MS-Access

    Was this answer helpful?

    0 comments No comments
  4. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2010-06-04T01:59:24+00:00

    On Fri, 4 Jun 2010 00:31:35 +0000, barraj75 wrote:

    In the Form_Current event write the code to unlock the field.

    -Tom.

    Microsoft Access MVP

    >

    >

    >I have a form that displays records, in one field in the record, if it is clicked, i would like to lock the other fields in that record only. How do you do this?

    >

    >I've put code in, however it locks those fields for every record... I only want it to affect the record that has that check box clicked.


    -Tom. Microsoft Access MVP

    Was this answer helpful?

    0 comments No comments