Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting unexpected response from keydown/press trap 1

Status
Not open for further replies.

BJZeak

Programmer
May 3, 2008
230
CA
Am I misunderstanding the keydown/press functions (MSA 3K)?

I have both a button and a keydown and or Keypress sub pointing at a subCancel routine

The cancel button works great and I am certain I have succesfully used these key routines somewhere else with no issues ... but today I am getting Object not found errors in the Parent Screen after I hit the ESC key. My understanding is that the Keycode and or Keyascii when set to 0 should ensure there is no further processing done with the captured key?

Yes I realize the Keydown fires before the Keypress but either one is having the same issue by themselves

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 And Shift = 0 Then
KeyCode = 0
subCancel
End If

End Sub


Private Sub btnCancel_Click()
subCancel
End Sub

Public Sub subCancel()
On Error GoTo Err_ccl

Dim CancelWO As String
CancelWO = "frmWO"
DoCmd.Close acForm, CancelWO, acSaveNo

Exit_ccl:
Exit Sub

Err_ccl:
MsgBox Err.description
Resume Exit_ccl

End Sub
 
Further info ... I set the Cancel switch on my cancel button and removed the Key traps and it behaves the same way ... starting to think there is some unwanted preprocessing going on with the ESC key.

 
How are ya BrixTreme . . .
[ol][li]For starters ... your closing the form with the [blue]Esc[/blue] key! I wouldn't recommend this as users are use to hitting this key for a number of reasons. Inadvertantly closing the form (espcially in the middle of editing) [blue]is sure to be maddening.[/blue] [mad][/li]
[li]You don't need both key events. So remove the [blue]KeyPress[/blue] event. What you you can do in keypress you can do in key down.[/li]
[li]Note: In order for the keycode to pass thru the keydown event (changed or not) and get back to the system, [blue]the event has to end![/blue] The point is ... setting the keycode to 0 (canceling Esc) fails, as you close the form before the event can complete! [surprise][/li]
[li]Perform your testing.[/li][/ol]
I recommend letting the users get use to hitting a button or doing something else to close the form, other than the Esc key.

[blue]Your Thoughts? . . .[/blue]



See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thank-you for the reply TheAceMan1

1) The child screen is normally an info screen ... I am old school I hate using mice especially in dirty shops ... we have keyboard condoms to protect from grease and grime which is kind of hard to do with mice. In addition there is always the data dirty flag for screens being edited which can be used to pull up an ARE YOU SURE YOU WANT TO CANCEL DIALOG.

2) I never use both these events in the same module

3) YES! :) I think you nailed the issue! :) Thank-you!
To complete the event all one would need to do is trigger a timed event ie set a state flag and start the timer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top