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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

KeyPress and KeyDown not working

Status
Not open for further replies.

SiberBob

Programmer
Aug 28, 2002
107
0
0
US
I can't seem to get either KeyPress or KeyDown to work on a userform in Excel 2000. Is that a known problem?

Here is my code:

Code:
Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = vbKeyPageUp Then GotoPreviousRecord
    If KeyCode = vbKeyPageDown Then GotoNextRecord
End Sub

Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    If KeyCode = vbKeyPageUp Then GotoPreviousRecord
    If KeyCode = vbKeyPageDown Then GotoNextRecord
End Sub

Thanks...

 
SiberBob,
I'm guessing that a control on your form has the focus, so that control is experiencing the KeyPress or KeyDown event, not the form.

The userform object does not have a built in mechanism to 'preview' the keys pressed before the individual controls do.

There have been a couple of posts on how to preview keyboard activity, try searching for WithEvents.

CMP

(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top