Share via

Make a form uneditable until click edit button

Anonymous
2011-05-15T11:29:30+00:00

Hi

I have created a form from a table now what i want is that it should be uneditable unit a user click a edit button.

So please tell me how to make a form uneditable and create a edit button.

Thanks

Amar

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

HansV 462.6K Reputation points
2011-05-15T11:48:04+00:00

Open the form in design view.

Activate the Event tab of the Property Sheet.

Select [Event Procedure] from the dropdown in the On Current event.

Click the builder buttons ... to the right of the dropdown arrow.

Make the code look like this:

Private Sub Form_Current()

    Me.AllowEdits = Not Me.NewRecord

End Sub

This will disable editing when the user loads an existing record, New records can still be created and edited.

Switch back to the form in Access.

Place a command button on the form. Make sure that the command button is selected.

Activate the Format tab of the Property Sheet and set the Caption property to Edit Record or whatever you prefer.

Activate the Other tab of the Property Sheet and set the Name property to cmdEdit.

Activate the Event tab of the Property Sheet.

Select [Event Procedure] from the On Click event, then click the builder buttons ...

Make the code look like this:

Private Sub cmdEdit_Click()

    Me.AllowEdits = True

End Sub

Was this answer helpful?

7 people found this answer helpful.
0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2011-05-16T12:43:21+00:00

If you want one control (or field) to be editable, you should NOT set AllowEdits to No, because that will lock the entire form.

Instead, work with the Locked property of the individual controls. If Locked = True, the user cannot edit the contents, and if Locked is False, the contents can be edited.

Set the Locked property of all text boxes, combo boxes, check boxes etc. to Yes in design view. Let's say that the combo box that you want to unlock is MyCombo. You can then use

Private Sub cmdEdit_Click()

    Me.AllowEdits = True

    Me.MySubform!MyCombo.Locked = True

End SubPrivate

Sub Form_Current()

    Me.AllowEdits = Me.NewRecord

    Me.MySubform!MyCombo.Locked = Me.NewRecord

End Sub

Was this answer helpful?

3 people found this answer helpful.
0 comments No comments

17 additional answers

Sort by: Most helpful
  1. Anonymous
    2011-05-16T09:30:31+00:00

    I have tried this on

    Private Sub Form_Current()

        Me.AllowEdits = Me.NewRecord

    End Sub

    Every thing is fine, the form is noneditable unit i click edit button but i also have sub datasheet in it which is still editable, so i also want to make it non editable unit a user clicks edit button.

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments
  2. HansV 462.6K Reputation points
    2011-05-24T07:54:26+00:00

    Sorry, I got it the wrong way round. Use

    Me.MySubform!MyCombo.Locked = Not Me.NewRecord

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2011-05-15T12:50:00+00:00

    I have tried writing the above code but it is still editable!!!!

    Was this answer helpful?

    0 comments No comments