A1: Automatic save
==============
The only way to guarantee you will catch every possible way that the record
could be saved in a bound form is to cancel the BeforeUpdate event of your
form.
Personally I would refuse to buy or use a program that forced me to use
click a ridiculous button like that. All it does is slow down a good data
entry operator, usually for no reason except that the developer did not
understand how to think event-driven.
But if you want to do it anyway:
1. In the General Declarations section (top) of the form's module:
Dim bAllowSave As Boolean
2. In the Before Update event procedure of your form:
Private Sub Form_BeforeUdate(Cancel As Integer)
If bAllowSave Then 'reset.
bAllowSave = False
Else 'prevent the save.
Cancel = True
MsgBox "You must use the Save button."
End If
End Sub
3. In the Click event procedure of your comand button:
Private Sub cmdSave_Click()
bAllowSave = True 'Permit the save
RunCommand acCmdSaveRecord
bAllowSave = False 'Reset.
End Sub
A2: Locking controls
===============
Presumably you are setting the Locked property of the bound controls because
if you set the AllowEdits property of the form that would disable all
controls on the form.
You therefore want a way to loop through all the controls on the form and
toggle the Locked property of just the controls bound to fields. There is a
function to do that in 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, ignores any that have no
Control Source property (such as labels and command buttons), ignores any
unbound controls and those bound to an expression, and toggles the Locked
property of the rest.
If it finds a subform, the code calls itself recursively, so subforms are
also handled to any depth.
If you have particular controls you do not want unlocked, you can list their
names in the exception list. So if you want to leave a subform unlocked, you
can name it in the exception list too.
It's actually very simple to use. To lock the controls, just:
Call LockBoundControls(Me, True)
and to unlock them:
Call LockBoundControls(Me, False)
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Kevin" <wi******@hotmail.com> wrote in message
news:pa****************************@hotmail.com...
I come up with these questions during the day, do some research, and then
look for experienced users' input.
1. In Access, we already know it's pretty much an automatic save if you
enter data. How can I prevent that? How can I make an effective way in
Access to not commit a change until a 'Save' button is pressed, and also
to backout changes using a 'Cancel' button?
2. Let's say I have 15 objects on a form, and they're locked. I have
Allow Edits set to yes. Is there some built-in function or procedure I
can call to unlock the objects, or do I need to call
Form_frmBlah.someobject.enabled for each one, or write me own function?
That's all for now. :)