Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    Manassas, Virginia, USA
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code for Escape key not working (Access 2002, SP 3)

    I am using the following code to return a form to its previous state if a user presses escape. In another Access database it works fine but when I use it in the database in which I am currently working I get an error message which highlights the word Keycode and says "Compile error: Variable not defined." In the other database where this is working, there is no dim statement for Keycode.

    Private Sub txtLastName_KeyPress(KeyAscii As Integer)
    If Keycode = vbKeyEscape Then
    Me.txtLastName = Null
    Me.txtAddStu.Visible = False
    Me.txtLastName.Visible = False
    Me.PWorkPhone.SetFocus
    Me.cmbStudent.Visible = False
    End If
    End Sub
    Judy Jones, Computer Training Specialist
    Manassas, Virginia

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Code for Escape key not working (Access 2002, SP 3)

    KeyCode is an argument in the On Key Down and On Key Up event procedures. The On Key Press event procedure uses KeyAscii instead.

  3. #3
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    Manassas, Virginia, USA
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code for Escape key not working (Access 2002, SP 3)

    Thank you. That's all it was. I thought I had pasted the code into the very same event but I hadn't. Thanks for your keen eye.
    Judy Jones, Computer Training Specialist
    Manassas, Virginia

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •