Block Editing

A

Andy

Hi;

Have a checkbox on the frm that when True blocks the record from being
deleted.

Want to add code that when True it also blocks a user from editing the data
in all fields on the frm except for the checkbox,

At Microsoft found: 210252 ACC2000: How to Use Code to Cycle Through the
Controls on a Form. The snippet LOCKS all txt and cbos. Graying out all
Controls.

Don't want that Gray. Want the controls on the frm to block a user from
editing the data.

Need code that blocks a user from editing the code but does not gray all the
controls and allows changes to the chkbx.

Found snippet that sets individual controls to dynamically locks a control
but that is done by including the name of each control on the form. Too
much bloat that way.

Would someone be so kind and point me in the right direction.

Andy
 
P

PC Datasheet

In your Code to Cycle Through the Controls on a Form, you need two lines:
Ctl.Locked = True
Ctl.Enabled = False
 
A

Andy

PC D;

Thank You for Your reply.

I'm aware of the:
Ctl.Locked = True
Ctl.Enabled = False

They cover all the Controls on the frm.

Need way to have the one Control that either "Protects/Un-Protests" editing
un-locked while all the rest of the Controls are "Protected" from being
edited.

Andy
 
M

Marshall Barton

Andy said:
Have a checkbox on the frm that when True blocks the record from being
deleted.

Want to add code that when True it also blocks a user from editing the data
in all fields on the frm except for the checkbox,

At Microsoft found: 210252 ACC2000: How to Use Code to Cycle Through the
Controls on a Form. The snippet LOCKS all txt and cbos. Graying out all
Controls.

Don't want that Gray. Want the controls on the frm to block a user from
editing the data.

Need code that blocks a user from editing the code but does not gray all the
controls and allows changes to the chkbx.

Found snippet that sets individual controls to dynamically locks a control
but that is done by including the name of each control on the form. Too
much bloat that way.


A common approach to this kind of thing is to set the Tag
property on the controls you want to lock to something like
LOCK. Leave the Tag property on the onther controls blank.
The code would then be slong these lines:

For Each ctl In Me
If ctl.Tag = "Lock" Then
ctl.Locked = Me.checkbox
ctl.Enabled = Not Me.checkbox
End If
Next ctl

That procedure should probably be executed from both the
check box's AfterUpdate event and the form's Current event.
 
D

Dale Fye

Andy,

Another way I handle this is not to set the forms "AllowEditing" property to
false. Then I have a command button (cmd_Edit) that changes that property
to True when clicked. This allows editing of the form. When this occurs, I
usually hide the Edit button and display two other buttons (Save and
Cancel). I also set the forms cycle property to CurrentRecord, so tabbing
out of the last control just cycles the focus to the first control on the
form. With this in place, the only way for someone to edit the record is to
click the Edit button. When they are done, they can select the Save or
Cancel button. Which will write the record or undo the changes. Clicking
one of the buttons unhides the edit button, sets the focus to that button,
sets AllowEditing back to False, and then hides the Save and Cancel buttons.

HTH
Dale
 
A

Andy

Thank You all for Your help.

Went with a chkBox to apply the AllowEdits = False, a cmdButton to remove
it, (AllowEdits = True), and a combination of:

Private Sub Form_Delete(Cancel As Integer)
Me.AllowEdits = False OR True
Forms![frmParent]![sfrmChild].Form.AllowEdits = False OR True

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Response = acDataErrContinue
DoCmd.GoToRecord acDataForm, "frmParent", acPrevious

Also added IF/THEN in OnCurrent for the chkBox.

PS for Dale, left the frm properties Allow Edits = Yes.

Thank You again.

Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top