Share via

Make a record read only

Anonymous
2018-01-05T22:40:24+00:00

I have a form based on a table in which one of the fields that is a check box. I want to make the entire record read only if this box is checked (i.e. all fields are read-only for that record).

This is the VBA code I have so far

Private Sub Form_Current()

If Me.Sent=True Then 'where sent is the field name of the check box

Form.AllowEdits=False

Form.AllowDeletions=False

Form.AllowUpdates=False

End If

End Sub

This didn't work because the fields on the form cannot be updated even for records where the box is unchecked.

I would appreciate your help

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

4 answers

Sort by: Most helpful
  1. Anonymous
    2018-01-08T22:33:52+00:00

    Probably  the simplest way is to conditionally lock/disable the subform control by adding this to the code I gave you earlier:

        With Me.[YourSubFormControlNameGoesHere]

            .Enabled = Not Me.Sent Or Me.NewRecord

            .Locked = Me.Sent And Not Me.NewRecord

        End With

    The subform control name is the name of the control in the parent form which 'houses' the subform.  It might or might not be the same as its source form object.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2018-01-08T20:43:36+00:00

    Thanks it worked. This form has a subform and I want to do the same thing for that, only that the check box is not on the subform. How would I accomplish that

    Was this answer helpful?

    0 comments No comments
  3. ScottGem 68,830 Reputation points Volunteer Moderator
    2018-01-08T02:42:49+00:00

    First, you have to understand this can only be done on a form. So you need to make sure users can't see the tables.

    Second, you have the right idea of sing the On Current event, but as Ken said you need to set the Allows to True if the box is not checked.

    However, there is a third point. In some scenarios you may have unbound controls on your form that you may need to edit whether you can edit the data or not. In that case I suggest looking at Allen Browne's function Lock Bound controls.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2018-01-05T22:59:16+00:00

    You need to set it both ways.  The easiest way to do this is to reference the value of the Boolean column to which the check box is bound, rather than the Boolean constants TRUE or FALSE:

        Me.AllowEdits = Not Me.Sent

        Me.AllowDeletions = Not Me.Sent

    There is no AllowUpdates property that I'm aware of.

    Was this answer helpful?

    0 comments No comments