LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Disable Change Event in Form

No problem - glad to help! I've never noticed that help says "KeyANSI", but
you're right - it sure does....

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


wrote:
Hi Jake,

Excellent idea! I didn't know setting KeyAscii to 0 would
surpress the keystroke. HELP has nothing about it. HELP
also says *KeyANSI* instead of *KeyAscii*, so I shouldn't
be too surprised.

I generalized your idea into a function I could call from
all of the text boxes and it seems to work nicely.

Thanks again,

David

--- code snippets ---

Private Sub Textbox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
KeyAscii = CheckKey(KeyAscii)
End Sub


Function CheckKey(ByVal KeyAscii As MSForms.ReturnInteger) As Integer
Dim i As Integer

i = InStr("/+*-.", Chr(KeyAscii))
' 12345
CheckSpecialKeyx = 0 ' Assume a match and we want to kill
' this key
Select Case i
Case 0 ' We're not interested
CheckSpecialKeyx = KeyAsciiin this key
Case 1 ' / = Toggle component textboxes
ToggleComponents
Case 2 ' + = Process data, dismiss form
CheckOut
Case 3 ' * = Toggle penalty textboxes
TogglePenalties
Case 4 ' - = Back-TAB
SendKeys "+{TAB}", False
Case 5 ' . = Delete textbox contents
ActiveControl = ""
ActiveControl.BackColor = rgbWhite
End Select
End Function


------------------------------------------------------------------------
Hi David,

You can use the KeyPress event to do something like that:

Private Sub TextBox1_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger) Select Case KeyAscii
Case Asc("+")
TextBox2.SetFocus
KeyAscii = 0
Case Asc("-")
TextBox3.SetFocus
KeyAscii = 0
End Select
End Sub

If the + key is pressed while in TextBox1, focus will move to
TextBox2. If - is pressed, focus goes to the previous TextBox.
Setting KeyAscii=0 within the event routine will supress the output
of that keystroke. You can also use this event routine to make sure
only numeric digits or +/- are pressed:

Private Sub TextBox1_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger) Select Case KeyAscii
Case Asc("+")
TextBox2.SetFocus
KeyAscii = 0
Case Asc("-")
TextBox3.SetFocus
KeyAscii = 0
Case Else
If InStr(1, "0123456789.", Chr$(KeyAscii)) = 0 Then
Interaction.Beep
KeyAscii = 0
End If
End Select
End Sub


 
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
KeyDown event on form Horatio J. Bilge, Jr. Excel Discussion (Misc queries) 0 October 26th 07 03:30 PM
Disable SelectionChange Event BillCPA Excel Discussion (Misc queries) 2 February 17th 06 06:45 PM
I need to disable to X on a user form cwwolfdog Excel Discussion (Misc queries) 2 March 28th 05 02:33 AM
change event/after update event?? scrabtree23[_2_] Excel Programming 1 October 20th 03 07:09 PM
Disable Worksheet change event Tim[_14_] Excel Programming 4 July 15th 03 01:27 AM


All times are GMT +1. The time now is 02:09 PM.

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

About Us

"It's about Microsoft Excel"