Delete Key does not trigger "On Key Up" event

  • Thread starter Thread starter Al Russcol
  • Start date Start date
A

Al Russcol

Hi All,

I am upgrading an Access 2.0 application to 2000 and have
a feature that does not work for properly.

In the original app, each control runs code triggered by
the "On Key Up" event to see if the record is dirty. If
so, the record movement is disabled and the user must
choose to save or cancel changes.

This works as expected in all but one case. When a
controls data is highlighted, (not edit mode) if the users
presses the "Delete" key, data is deleted but the it seems
that the event is not triggered and the user can change
records thereby unintentionally saving changes. Touching
any key thereafter, (even the delete key) triggers the
event with the expected behaviour. I tried the "On Key
Down" and "On Key Press" events with the same results.
Possibly this is related to being in edit mode within the
control but I am stumped. This never came up when running
on 2.0 but I do not have an easy way to check this anymore.

I searched the knowledge base plus help and found nothing
about this problem but perhaps someone out there has run
into this before or has a suggestion.

There is always the "Before Update" event but I would
prefer not to change the way this works and I am very
curious why the delete key does not trigger the event. Is
this behaviour by design?

Thanks,

alr
 
Al-

When all the text is highlighted, the control fires Key Down for the delete
key, but then Access "traps" the key because it has a special meaning -
delete all the text. The Delete is never delivered to the text box in Key
Press or Key Up. If the text box has a cursor (by pressing F2), then you
will see both Key Down and Key Up, but not Key Press when the user presses
the Delete key to delete one character.

In Access 2000, try using the form's On Dirty event instead. That's a lot
easier than trying to trap keystrokes.

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
http://www.deanforamerica.com/site/TR?pg=personal&fr_id=1090&px=1434411
 
Hi John,

Thanks very much thatis a great suggestion except for one
thing, the behaviour is exactly the same as the On Key
events.

I would prefer to leave the user interface as close to the
current state as possible. Is is possible to supress
Acess' trapping this event or responding to this key press
by another means?

Also to you happen to know if this behaviour was different
in Access 2.0? (I don't think I have a box that would run
2.0 even if I could find it)

Thanks,

alr
 
*Why* don't you want to use Form_BeforeUpdate? It seems like the right event
for you. If the user dirties the record, then tries to move to a new record,
Form_BeforeUpdate will fire, & you can do what you need to, there.

Yes? No?

HTH,
TC
 
Hi TC,

The current set-up changes as soon as a key is pressed.
The ADDNEW button disapears and a SAVE and UNDO buttons
appear. Also the record navigation buttons are disabled. I
would prefer to leave things as close to what they have as
possible.

This is not an enourmous issue but I would like to
understand it fully in any case.

Thanks,

alr
 
The On Dirty event seems to be firing at the correct time - even in the
Delete key condition that you mentioned. Using this should greatly simplify
the code behind your form. I assume you have Key Up code defined for every
control. If you use the Form (not the control) Dirty event, you can write
the code once for each form. If you tried the control Dirty event, that
won't fire with the Delete key.

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
http://www.deanforamerica.com/site/TR?pg=personal&fr_id=1090&px=1434411
 
Sorry. Forgot to answer your second question. I don't have V2 installed
anywhere, so I can't specifically test it. Because of the major
architectural change from V2 to Access 95, I wouldn't be surprised if the
event changed. It makes sense to me that Key Up does not occur for the
Delete key in a text box that has all its text highlighted. Could have been
a "bug" in V2 that they fixed in V7.

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
http://www.deanforamerica.com/site/TR?pg=personal&fr_id=1090&px=1434411
 
Back
Top