Question about Keyascii and If/Then statements

maxxximaniac

Registered User.
Local time
Yesterday, 16:52
Joined
Oct 22, 2004
Messages
80
Hey guys,

This is probably gonna be cake for some of you, but it not workin right for me.

I have this statement in a form under KeyPress
What I need to to is Add another allowed Key, Backspace,
Can someone help me code this?

Code:
If KeyAscii < 47 Or KeyAscii > 57 Then KeyAscii = 0


Thanks!
 
KeyAscii

Try this:

If KeyAscii = 8 Or KeyAscii > 47 And KeyAscii < 58 Then
KeyAscii = KeyAscii
Else
KeyAscii = 0
End If
 
If KeyAscii < 47 Or KeyAscii > 57 Or KeyAscii = whatever Then KeyAscii = 0
 
Select Case is probably easier: -

Code:
Option Explicit
Option Compare Text


Private Sub Form_KeyPress(KeyAscii As Integer)

    Select Case KeyAscii
        Case 8, 47 To 57
            [color=green]'  Do Nothing[/color]
            
        Case Else
            KeyAscii = 0
    
    End Select

End Sub
Hope that helps.

ETA…
Good morning Pat, didn’t see you there. :)


Regards,
Chris.
 
Last edited:
or on 1 line,
If KeyAscii < 47 And KeyAscii <> 8 Or KeyAscii > 57 Then KeyAscii = 0
 

Users who are viewing this thread

Back
Top Bottom