View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff Harald Staff is offline
external usenet poster
 
Posts: 1,327
Default Prevent "standard" key event in userform

"Oskar von dem Hagen" skrev i melding
...
(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. :-) )

Reading books like that makes you more than "most excel users" ;-)

I was surprised not to find a ready solution in the newsgroup. What do

other authors do, force people to use the mouse?

When you've done this a few times it't pretty quick to set up again. There
will always me more scenarios than ready-to-go solutions.

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?

The class module is NOT in the userform, it is simply a collection of
abstract rules of behavior for a userform textbox.

This is purist stuff, but still: You have more than one way to call the
"Next whatever" action. PgUp, buttonclick and maybe morenow or later. Then
do not place the action in the button code, separate it and call it from
wherever. Put this in the userform module:

Public Sub NextRec()
MsgBox "Next"
End Sub

Public Sub PrevRec()
MsgBox "Previous"
End Sub

and make your button code do this:

Private Sub BnNext_Click()
NextRec
End Sub

Private Sub bnPrevious_Click()
PrevRec
End Sub

Now (note the Public in the subs) you can call it also from everywhere as
long as you address it. Edit your class code to

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

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


That's norwegian. So am I :-)

HTH. Best wishes Harald