Subforms, Dirty Records & The Escape Key

C

Cascot

I'm going around in circles here, and any help would be much
appreciated.

I have a form with several controls (comboboxes and textboxes) aimed at
gathering information for a sales order. There is a subform with
buttons above it for adding, editing and deleting sales items from the
order. Here are the problems I'm having...

1. If I have the subform enabled, tabbing through the controls (or
clicking the mouse into the subform if I set "TabStop = No" for the
subform) equates to moving off the record. I get errors raised at that
point if the record has been dirtied but every required field does not
yet contain data. So I disable the Subform until all required fields
contain data.

This just doesn't feel like a great approach, of course neither does
removing database level validation in tems of setting fields as being
required.

2. OK, so now the form behaves acceptably, enter the wonderful "Escape"
key. On many other forms I have thus far designed for the system, I use
the Form_Error procedure to capture error 2107 (The value you entered
entered doesn't meet the validation rule defined for the field or
control) and error 3314 (Entry required in this field, cannot contain
a Null value). Apparently the standard is that if you have typed over a
valid entry with invalid data you can restore the previous value by
pressing the escape key. This worked on my other forms, but on the form
I describe at the opening, pressing the escape key always closes the
form instantly, no matter what. As you can imagine this is very, VERY
far from perfect.

Can anyone shed any light on use of the Escape key, why it works on
other forms in terms of returning controls to their previous values,
yet on this form it always closes the form? I know I can catch any use
of the escape key and prevent form closure, but what I really want is
it to work the same way it does on my other forms, namely restoring the
original value of a control.

Any suggestions what I am missing here, or what I'm doing completely
incorrectly?
 
A

Albert D.Kallal

Yes...if you set a button's "cancel" property to true, then that button
fires when you hit escape.

And, if you set a buttons "default" property to true..then that buttons
fires when you hit enter...

this is a great feature, since then for forms that prompt....and have a"ok"
button, the user can use the keyboard..and hit "enter" key to fire the ok
button.

So, check your buttons "cancel" properties...since any button set to yes
will fire when esc key hit....
 
C

Cascot

Albert,

Thank you so much. That is certainly the part I hadn't picked up on. I
should have as I knew from code breaks that the Cancel command button
code was being fired, but didn't link "Escape" with the "Cancel Button
= True" property setting.

That has helped me to remove some of the confusion, but I am still
having problems.

Let's say a user enters data in all the required data fields, plus code
has entered data into some fields behind the scenes, and as a
consequence the user is allowed to add an item to the Order (i.e. the
subform is enabled). They add an item or three and return to the main
Order form where they now see the 3 items just added in the subform.
Now the user presses the escape key. The record gets cleared out. The
user then tabs into the subform or clicks the mouse somewhere on the
subform. This raises an error as now the user is moving off the parent
record when all required fields are no longer populated.

Maybe I should "catch" any pressing of the Escape key but this doesn't
seem right. In the same breath I clearly can't have errors being raised
when the above scenario plays out. Or maybe I could disable the subform
when/if the record is undirtied?

It all seems very messy.

Can you offer any ideas or suggestions?
 
J

John Vinson

They add an item or three and return to the main
Order form where they now see the 3 items just added in the subform.
Now the user presses the escape key. The record gets cleared out.

Actually, it doesn't. The record has already been saved to disk, the
moment the user set focus to the subform.

John W. Vinson[MVP]
 
C

Cascot

John,

Thanks for your reply.

I agree that using the example of typing directly into the table that
is what ought to be happening, and thus a return to the parent record
and a press of the Escape key should no longer clear out that record,
only undo any changes made since returning to it. So I cannot explain
what is happening, hence the posting.

I should also have been more precise. When I said "record gets cleared
out" I should have said the values of all the controls on the form get
cleared (that may actually be returned to their original values, I'm
not exactly sure). Either way the combo boxes and textboxes get cleared
out, thus tabbing into or clicking on the subform then raises errors
such as 2107 or 3314.

Any ideas?
 

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