View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Steve Garman Steve Garman is offline
external usenet poster
 
Posts: 107
Default Prevent "standard" key event in userform

The buttons do have something in their click event, don't they?
You are only calling the click event, you are not clicking the button.

Also, are you sure your textbox is called txtbox and has the focus?


This works OK he

Private Sub bnNext_Click()
MsgBox "next"
End Sub

Private Sub bnPrevious_Click()
MsgBox "previous"
End Sub

Private Sub txtbox_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Select Case KeyCode
Case 34
bnNext_Click
Case 33
bnPrevious_Click
Case Else
Exit Sub
End Select
KeyCode = 0
End Sub


Oskar von dem Hagen wrote:
Thanks. Apparently I have to use KeyDown to catch PgDn or PgUp. (Bullen et al. write "Most VBA users will never have to create their own objects because Excel already provides all of the objects they need." That's why I skipped the chapter on class modules. :-) )

I was surprised not to find a ready solution in the newsgroup. What do other authors do, force people to use the mouse?

My hopefully last problem in this thread is probably trivial but I haven't figured it out yet. Why does the class modul not recognize the subroutine bnNext_Click, containd in the UserForm in the same Project? And how can I change this.

Private Sub txtbox_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case 34
bnNext_Click
Case 33
bnPrevious_Click
Case Else
Exit Sub
End Select
KeyCode = 0
End Sub

Oskar

P.S. I love the "skrev i melding".