473,652 Members | 3,123 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.so meobject.enable d for each one, or write me own function?

That's all for now. :)
Jan 18 '06 #1
6 1608
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_BeforeUdat e(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 LockBoundContro ls(Me, True)
and to unlock them:
Call LockBoundContro ls(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******@hotma il.com> wrote in message
news:pa******** *************** *****@hotmail.c om...

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.so meobject.enable d 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******@hotma il.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******@hotma il.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_BeforeUpda te(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_BeforeUpda te 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******@hotma il.com> wrote in message
news:pa******** *************** *****@hotmail.c om...
On Wed, 18 Jan 2006 04:40:36 +0000, Wayne Gillespie wrote:
On Wed, 18 Jan 2006 04:14:30 GMT, Kevin <wi******@hotma il.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_BeforeUpda te 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
2113
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 where I
2
1841
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 a child form. Two questions: 1) Does the user need IE to get this control working? 2) I cancel the closing of the child form in it's FormClosing event and
2
1496
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 handling all the non-object chores. The Problem: The object/control has as one of its properties 'FileName' which is a string. I need to pass the value of that property to some container so that my Codebehind page will have access to the value of...
2
1347
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 windows forms control and mark them asa serializable? Does anybody know an easy way for this?
0
955
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 view and save each control? I'm hoping there is an easier way! Thanks for any suggestions, Tim
0
1293
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 automatically so that I don't have to set this sytle every time? 2. I'd like to code have a "New" button, that when selected makes visible a detailview in insert mode and with only the insert command available. I would imagine I'd be adding an...
2
2149
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 Outlook.ApplicationClass(); Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");Outlook.MAPIFolder oContacts = olApp.ActiveExplorer().CurrentFolder; Object selObject = olApp.ActiveExplorer().Selection;
0
999
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 control that is using the SqlDataSource as it's data source. Everything works great with respect to displaying the contents of the data base. My problem is two parts: How do I make the fields of the gridview editable and how would I add update and...
7
1146
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 issues around this and have some mitigation of them in that the site is a 'private internet site' - IPs locked to the users offices. I have tried many options in terms of zones, but all throw (unsurprisingly) security issues.
0
8367
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8811
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8467
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8589
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4145
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.