Trap Keypress to igmore non numeric entries 
Author Message
 Trap Keypress to igmore non numeric entries

Can this be done?


Sat, 11 Aug 2001 03:00:00 GMT  
 Trap Keypress to igmore non numeric entries
Hi Richard,

Set the form's KeyPreview property to True and use the KeyDown event like
this.

'****** Code Start *******
Private Declare Function apiIsCharAlpha Lib "user32" _
  Alias "IsCharAlphaA" _
  (ByVal cChar As Byte) _
  As Long

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim bytChar As Byte
  bytChar = KeyCode
  If apiIsCharAlpha(bytChar) Then
    KeyCode = 0
  End If
End Sub
'******* Code End ******

HTH
--
Dev Ashish (Just my $.001)
---------------
The Access Web ( http://home.att.net/~dashish )
---------------


:Can this be done?
:
:



Sat, 11 Aug 2001 03:00:00 GMT  
 Trap Keypress to igmore non numeric entries
Hi Richard,

Set the form's KeyPreview property to True and use the KeyDown event like
this.

'****** Code Start *******
Private Declare Function apiIsCharAlpha Lib "user32" _
  Alias "IsCharAlphaA" _
  (ByVal cChar As Byte) _
  As Long

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim bytChar As Byte
  bytChar = KeyCode
  If apiIsCharAlpha(bytChar) Then
    KeyCode = 0
  End If
End Sub
'******* Code End ******

HTH
--
Dev Ashish (Just my $.001)
---------------
The Access Web ( http://home.att.net/~dashish )
---------------


:Can this be done?
:
:



Sat, 11 Aug 2001 03:00:00 GMT  
 Trap Keypress to igmore non numeric entries
Dev, you're a real api-fan aren't you!
Couldn't you just use if not isnumeric ?


Sun, 12 Aug 2001 03:00:00 GMT  
 Trap Keypress to igmore non numeric entries
Testing for
  KeyCode Like "#"
would also do it.

Simon Lewis



Sun, 12 Aug 2001 03:00:00 GMT  
 Trap Keypress to igmore non numeric entries

Quote:
> Dev, you're a real api-fan aren't you!
> Couldn't you just use if not isnumeric ?

Sometimes one gets into a mindset, because of what one is working on at
the moment.  It's always too easy to look for a solution in the area
you're currently pondering.

I like using "Like #" myself -- and it turns out that, if I remember
correctly, this is faster than using the API call, in Access (but not in
VB -- though I don't know why ...) -- Ken



Sun, 12 Aug 2001 03:00:00 GMT  
 Trap Keypress to igmore non numeric entries


Quote:
>Can this be done?



Sun, 12 Aug 2001 03:00:00 GMT  
 Trap Keypress to igmore non numeric entries
I appted for this:

  Select Case ikeycode
    Case 8 To 9
      ikeycode = ikeycode
    Case Is = 13
      ikeycode = ikeycode
    Case Is = 27
    ikeycode = ikeycode
    Case Is = 46
      ikeycode = ikeycode
    Case 47 To 57
      ikeycode = ikeycode
    Case 96 To 105
      ikeycode = ikeycode
    Case Else
      ikeycode = 0
  End Select

can I use a function for this and call the function.  I may have several
txtboxes that I would like to implement this validation...


Quote:
>Can this be done?



Sun, 12 Aug 2001 03:00:00 GMT  
 Trap Keypress to igmore non numeric entries
Thanks ET..  I had the MSDN open in front of me at that time. <g>

PS: Did ya hear the echo from me slapping my forehead? :-)

    -- Dev

:Dev, you're a real api-fan aren't you!
:Couldn't you just use if not isnumeric ?
:
:



Sun, 12 Aug 2001 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Defaults for non-numeric fields in a data entry form

2. Counting non numeric entries in a column

3. ANOVA with data that contains numeric and non-numeric data

4. Numeric vs Non Numeric ?

5. Routine to transform a Numeric into a non Numeric

6. Regression analysis: non-contiguous data, non-numeric data

7. Trapping Onkey or Keypress in UserForm : please help

8. Trapping keypress or KeyDown in worksheet

9. Trap Page-Down KeyPress

10. Trapping KeyPresses - Still Having difficulties


 
Powered by phpBB® Forum Software © phpBB Group