Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Prevent "standard" key event in userform

In found out (see "PgDn in Userform") how to capture the pressing of PgDn with keypressed and try to use it to read the next record into the form

Unfortunately, the "standard event" is executed too. I.e. PgDn in a combo box get the new record (fine) but also changes the value of the combo box (not fine)

Any way to prevent this

Oska

P.S. I don't know if starting a new thread is a correct procedure to draw (renewed) attention to an old thread. If not, I would like some illumination.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Prevent "standard" key event in userform

Solves the Problem. Thanks

My problem in "PgDn in UserForm" (http://communities2.microsoft.com/co...figuration.xml - is there a shorter way to cref?) was to use PgDn as bnNext_Clixk everywhere in the userform

With dozens of controls I am reluctant to include the code for every field. Is there a more elegant way

Oska

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Prevent "standard" key event in userform

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 KeyCod
Case 3
bnNext_Clic
Case 3
bnPrevious_Clic
Case Els
Exit Su
End Selec
KeyCode =
End Su

Oska

P.S. I love the "skrev i melding".
  #4   Report Post  
Posted to microsoft.public.excel.programming
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".


  #5   Report Post  
Posted to microsoft.public.excel.programming
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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Prevent "standard" key event in userform

Thanks Harald and Steve. I misread the help-file and was of the erroneous opinion that "Private" means private to a project, but it means private to a module. Private to a project apparently requires "Public" plus "Option Private Module"

I tried "Public" and userform1.bnNext_Click - but not in combination. :-

Now it works
Oskar
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use "standard deviation" option in Y error bar menu? Michael Levin Charts and Charting in Excel 1 April 24th 10 01:35 AM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
In Excel 2003 is there a way to prevent "Save As" and "Print"? lucky2000 Excel Discussion (Misc queries) 3 April 26th 07 02:49 PM
Standard font in a "New Microsoft Excel Worksheet.xls" wont change Prunetart Excel Discussion (Misc queries) 0 September 15th 06 10:36 AM
Prevent "standard" key event in userform Harald Staff Excel Programming 0 May 28th 04 11:36 PM


All times are GMT +1. The time now is 01:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"