Results 1 to 8 of 8
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919

    Esc key not triggering Undo Event

    First time user of the Esc key to trigger the Undo Event................which isn't firing when tested.



    Is my understanding of the Esc key incorrect? I have VBA event procedure code behind the form's Undo Event, but it does not execute when the Esc key is pressed.

  2. #2
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    This approach doesn't work either.

    Code:
    Private Sub Form_KeyPress(KeyAscii As Integer)
    
    If KeyAscii = vbKeyEscape Then
        MoveDonation = 0
        Me.DonationsSubform.Visible = True
        Me.lblMovePrompt.Visible = False
    End If
    
    End Sub

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    Sorry, meaning it doesn't fire either when Esc is pressed.

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Using <Esc> to undo isn't exactly straight-forward! See if this explains it:

    • If you enter data, say in ControlA, then hit <Esc> the data in ControlA is undone and the Form_Undo event will fire
    • If you enter data in ControlA, then enter data in ControlB and then hit <Esc>...the data in ControlB will be undone...but the Form_Undo event will not fire!
    • If you hit the <Esc> key once more, the data in ControlA will be undone and the Form_Undo event will then fire!

    Confused enough? To restate it, if data has been entered/edited in one Control and <Esc> is hit, that Control is undone and because it is the only Control that can be undone, the Form, itself, is considered to be undone and Form_Undone fires.

    If more than one Control has had data entered, and <Esc> is hit twice, the first hit undoes the last Control entered while the second hit undoes all other Controls and the Form, itself, is considered undone, and Form_Undone fires.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    It would seem that I've chosen the wrong event. The case is this: I have a case where the user has started a function wherein the "ownership" of a given record is to be re-asigned to a new owner. The first part of the function makes a sub-form container "not visible" and makes a label control visible, the label being a simple prompt message for the user's next action. I just want at the point to give the user the option of cancelling the operation, which would be a simple case of reverting the visibility of the two controls.

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    I couldn't get ANY of the "key" events to fire wherein I would have looked for vbKeyEscape.

    No more time to spend on this. I added "(Click here to cancel)" to the function prompt label and put the necessary code in the label's OnClick event.

    Thanks for everyone's thoughts.
    Bill

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by GraeagleBill View Post

    ...I couldn't get ANY of the "key" events to fire...
    I understand that you've moved on, but for future reference, in order to use the KeyPress events, the Form's KeyPreview Property has to be set to Yes. When you go looking for it this property is the very, very last property listed on the Form's Events Tab.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    Thanks Linq. I tested the KeyPress event successfully having enabled "Key Preview".

    Bill

Please reply to this thread with any new information or opinions.

Similar Threads

  1. MS Access triggering Outlook Security warning
    By Amiga1200 in forum Programming
    Replies: 5
    Last Post: 05-22-2014, 11:24 PM
  2. Replies: 5
    Last Post: 05-09-2014, 08:12 AM
  3. Replies: 2
    Last Post: 11-28-2012, 10:32 AM
  4. Triggering a form event from a report
    By Paul H in forum Forms
    Replies: 2
    Last Post: 10-12-2012, 09:48 AM
  5. Replies: 2
    Last Post: 01-17-2012, 01:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums