Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to use "standard deviation" option in Y error bar menu? | Charts and Charting in Excel | |||
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell | Excel Discussion (Misc queries) | |||
In Excel 2003 is there a way to prevent "Save As" and "Print"? | Excel Discussion (Misc queries) | |||
Standard font in a "New Microsoft Excel Worksheet.xls" wont change | Excel Discussion (Misc queries) | |||
Prevent "standard" key event in userform | Excel Programming |