Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Help with KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

Hi everyone,

the code below works sometimes, and other times it doesn't work. I dont know
why, can someone help me figure out why.

Private Sub txtItemFob_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 8 To 10, 13, 27 'Control characters
Case 45, 46 'negative and period
If KeyAscii = 45 Then 'hypen/negative
If Len(Trim(txtItemFob.Text)) 1 Then
Beep
KeyAscii = 0
End If
End If
Case 48 To 57 'numbers
Case Else 'Discard anything else
Beep
KeyAscii = 0
End Select
End Sub


thanks
ernie
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Help with KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

Ernie,

Give this a try.


Private Sub txtItemFob_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 8 To 10, 13, 27 'Control characters
Case 45 'negative
If Len(Trim(txtItemFob.Text)) = 1 Then
Beep
KeyAscii = 0
End If
Case 46 'period
If InStr(1, txtItemFob.Text, ".") 0 Then
Beep
KeyAscii = 0
End If
Case 48 To 57 'numbers
Case Else 'Discard anything else
Beep
KeyAscii = 0
End Select
End Sub




--
Hope that helps.

Vergel Adriano


"ernie" wrote:

Hi everyone,

the code below works sometimes, and other times it doesn't work. I dont know
why, can someone help me figure out why.

Private Sub txtItemFob_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 8 To 10, 13, 27 'Control characters
Case 45, 46 'negative and period
If KeyAscii = 45 Then 'hypen/negative
If Len(Trim(txtItemFob.Text)) 1 Then
Beep
KeyAscii = 0
End If
End If
Case 48 To 57 'numbers
Case Else 'Discard anything else
Beep
KeyAscii = 0
End Select
End Sub


thanks
ernie

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
keyascii = 13 ermeko Excel Programming 3 December 2nd 06 06:38 PM
MSForms.ReturnInteger assignment Tim[_44_] Excel Programming 0 January 11th 06 09:50 PM
How to populate an MSForms.ReturnInteger value Tim[_44_] Excel Programming 0 January 10th 06 07:36 PM
"ByVal Cancel As MSForms.ReturnBoolean" rbyteme Excel Programming 3 October 12th 05 04:32 PM
Call Sub Procedure object_Exit(ByVal Cancel As MSForms.ReturnBoole Kevin McCartney Excel Programming 1 October 8th 04 10:37 AM


All times are GMT +1. The time now is 05:13 PM.

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"