Preventing changes in a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form which displays records. Everything works.
Users are accidentally changing data on the form and not realizing it.
I still need the ability to make changes to the records.

Is there a way I can tell access to only allow changes by hitting a key
combo or something like that?

Mike
 
Mike, you can set the form's AllowEdits property to No, until they click a
button that sets it to Yes if they need to edit. You probably want to set
AllowDeletions also.

The practial issue with that approach is that it locks all controls on the
form, including any unbound ones. That means you can no longer use an
unbound unbound controls to act as filters or to jump to a matching record.
If you need to do those kinds of things, you will need to set the Locked
property of the bound controls instead of the AllowEdits property of the
form.

You can get the code to do that from this link:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

The code loops through all controls on the form, identifies if they are
bound controls, and locks or unlocks them. If it finds a subform, it calls
itself recursively, so that any subforms are also locked/unlocked to any
nested depth. You can optionally specify the names of controls that you
don't want locked, so if you did not want your subform locked as well,
include it in the exception list.

Finally, it suggests adding a red rectangle around the edge of the detail
section as a visual indicator of when the record is locked.
 
Ofer said:
Hi Mike
On the BeforeUpdate event of the form you ca write the code

If Me.Dirty Then ' Indicate if data has changed
If MsgBox("Data has changed, save changes?", vbOKCancel) <> vbOK
Then ' Undo changes
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End If
End If

Just as a note: there's no need to check Me.Dirty in the form's
BeforeUpdate event. That event cannot fire if the form isn't Dirty.
 
Back
Top