473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

A few more questions - saving, canceling, object control


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. :)
Jan 18 '06 #1
6 1578
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. :)

Jan 18 '06 #2
On Wed, 18 Jan 2006 11:57:29 +0800, Allen Browne wrote:
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.
[snip]


Ok, then let me ask you this. How do you help ensure the data is what
should be in there? If said operator starts a new record and begins
typing, then decides - oh, I don't want this after all - what's the Access
way to handle it? Delete the record? I'm just trying to think "dumb
operator" proof. :)
Jan 18 '06 #3
On Wed, 18 Jan 2006 04:14:30 GMT, Kevin <wi******@hotmail.com> wrote:
On Wed, 18 Jan 2006 11:57:29 +0800, Allen Browne wrote:
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.
[snip]


Ok, then let me ask you this. How do you help ensure the data is what
should be in there? If said operator starts a new record and begins
typing, then decides - oh, I don't want this after all - what's the Access
way to handle it? Delete the record? I'm just trying to think "dumb
operator" proof. :)


Press {Esc} twice.

The first {Esc} undoes changes to the current control.
The second {Esc} undoes all changes to the current record.

If you are working on a saved record, pressing {Esc} twice will restore the record to it's last saved state. If you are
working on a new record it will cancel the new record.
Wayne Gillespie
Gosford NSW Australia
Jan 18 '06 #4
On Wed, 18 Jan 2006 04:40:36 +0000, Wayne Gillespie wrote:
On Wed, 18 Jan 2006 04:14:30 GMT, Kevin <wi******@hotmail.com> wrote:
On Wed, 18 Jan 2006 11:57:29 +0800, Allen Browne wrote:
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.
[snip]


Ok, then let me ask you this. How do you help ensure the data is what
should be in there? If said operator starts a new record and begins
typing, then decides - oh, I don't want this after all - what's the
Access way to handle it? Delete the record? I'm just trying to think
"dumb operator" proof. :)


Press {Esc} twice.

The first {Esc} undoes changes to the current control. The second {Esc}
undoes all changes to the current record.

If you are working on a saved record, pressing {Esc} twice will restore
the record to it's last saved state. If you are working on a new record it
will cancel the new record.


Well, that's a good thing to know. But how do I tell any user that may use
it?

I might just do the lock/unlock option like Allen's page has, and leave it
up to the operator to know what they're entering. It's a small database,
so I guess it's not such a big deal - just trying to provide some
additional data integrity.
Jan 18 '06 #5
Kevin, for users who have no idea what they are doing, I have sometimes
implemented a save confirmation just by using the BeforeUpdate event of each
form:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If gbcConfirm Then
If MsgBox("Save?", vbOkCancel) = vbCancel Then
Cancel =True
MsgBox "Correct the entry, or press <Esc> twice to undo."
End If
End If
End Sub

Then in a standard module (through the Modules tab of the Database window),
add this line to the top of a module (just under the Option statements):
Public Const gbcConfirm = True

Later, when the user is tired of the confirmation dialogs, you can turn it
off for all forms just by changing that line to:
Public Const gbcConfirm = False

(BTW, every bound form I create has code in Form_BeforeUpdate to check that
everything is okay before the record is saved.)

--
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...
On Wed, 18 Jan 2006 04:40:36 +0000, Wayne Gillespie wrote:
On Wed, 18 Jan 2006 04:14:30 GMT, Kevin <wi******@hotmail.com> wrote:
On Wed, 18 Jan 2006 11:57:29 +0800, Allen Browne wrote:

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.
[snip]

Ok, then let me ask you this. How do you help ensure the data is what
should be in there? If said operator starts a new record and begins
typing, then decides - oh, I don't want this after all - what's the
Access way to handle it? Delete the record? I'm just trying to think
"dumb operator" proof. :)


Press {Esc} twice.

The first {Esc} undoes changes to the current control. The second {Esc}
undoes all changes to the current record.

If you are working on a saved record, pressing {Esc} twice will restore
the record to it's last saved state. If you are working on a new record
it
will cancel the new record.


Well, that's a good thing to know. But how do I tell any user that may use
it?

I might just do the lock/unlock option like Allen's page has, and leave it
up to the operator to know what they're entering. It's a small database,
so I guess it's not such a big deal - just trying to provide some
additional data integrity.

Jan 18 '06 #6
On Wed, 18 Jan 2006 14:49:37 +0800, Allen Browne wrote:

(BTW, every bound form I create has code in Form_BeforeUpdate to check
that everything is okay before the record is saved.)


Thanks Allen,

I guess I need to do a little more research into the BeforeUpdate and
other events.

Kevin
Jan 18 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: John Marshall | last post by:
Hi, Does anyone see a problem with doing: data = file("tata").read() Each time this is done, I see a new file descriptor allocated (Linux) but not released. 1) Will there ever be a point...
2
by: frederik12 | last post by:
Hi all, Today I downloaded and installed VS 2005 C# Express Edition (.NET framework 2.0). I'm very pleased about this new product. In my current application I'm using the WebBrowser control in...
2
by: seth | last post by:
The Environment: I have a 3rd party control referenced as an object on an aspx page with inline code in script tags accessing the methods of properties of same. I also have a Codebehind page...
2
by: Özden Irmak | last post by:
Hello, Is there an easy way to save some/all properties of a windows forms control into a type of file? I came acros with "Serializable" attribute but it seems that I have to inherit evey...
0
by: Tim_k | last post by:
Hi, I have a multiview control with several views. Is there an easy way to save this control and restore it when I return to the page? Or, do I have to walk through the controlarray for each...
0
by: webmaster | last post by:
I've been playing around with asp.net 2.0/vs.net 2005/C# 2005 - I had a few noob questions. 1. Is there a setting that sets all current and future controls on a page to position absolutely...
2
by: Kannan | last post by:
Hi, I am trying to save Inbox selected message in C: I have used following code string SavedMessage = "C:\\AIA\\Message\\"; string strSaveName = "Test.msg"; Outlook._Application olApp = new...
0
by: zoneal | last post by:
I am trying to learn asp.net and have run into a wall with a problem. Can anyone help me through this problem? I am using the SqlDataSource (set to an Access data base). I have a grid view...
7
by: mrmoosehead | last post by:
OK. I am trying to embed a control in a webpage that will allow local access to the TAPI system to make and query phone calls. In a nutshell. Anyway, I am aware that there are many security...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.