I know this is an easy one. I have found the answere, but It wasnt quite what i wanted, and it didnt work for me. Can I have some quick help thanks! :)
Printable View
I know this is an easy one. I have found the answere, but It wasnt quite what i wanted, and it didnt work for me. Can I have some quick help thanks! :)
Post the code you think is close, and identify the deficiencies.
(This question has been answered many, many times before)
Bruce.
This code doesnt work. When i enter a normal character into the textbox, it shows nothing:
I also want to be able to do NON upper case letters also.VB Code:
Private Sub Text2_KeyPress(KeyAscii As Integer) If Not (KeyAscii > 47 And KeyAscii < 58) Or (KeyAscii > 64 And KeyAscii < 91) Or (KeyAscii > 96 And KeyAscii < 123) Or (KeyAscii = 95) Then KeyAscii = 8 End If
You wern't evaluating all other NOT's, so try:
VB Code:
Option Explicit Private Sub Text2_KeyPress(KeyAscii As Integer) If Not ((KeyAscii > 47 And KeyAscii < 58) Or (KeyAscii > 64 And KeyAscii < 91) Or (KeyAscii > 96 And KeyAscii < 123) Or (KeyAscii = 95)) Then KeyAscii = 0 End If End Sub
Bruce.
Thanks. That's what i needed.
To clarify: I enclosed the whole 'Or AND' structure (with ()), and if that
was evaluated, then send KeyAscii = 0.
Bruce.
Although that works for the user typing in the TextBox, you should also check the data thats Cut 'n' Pasted!
One (probably the best) method is to use the Text2_Validate() Event, and if there is an unwanted character, then highlight it and
set the Validation's Cancel = False (kepping the Focus in the TextBox until its correct)
Bruce.
with the coding you sent me, the user CANT cut and paste! it doesnt allow for ctrl.
...If the user uses the mouse, I have coding that says something like "If len(text2.text) = 0 then"...
Quote:
Originally posted by squakMix
with the coding you sent me, the user CANT cut and paste! it doesnt allow for ctrl.
Ahhh, I should have checked that :)
Quote:
Originally posted by squakMix
...If the user uses the mouse, I have coding that says something like "If len(text2.text) = 0 then"...
Not too sure if you indend that (above) to counter the use of the Mouse|Paste....
I was able to paste unwanted characters using the Right Mouse Button.
Again, you may have taken care of that.
yea, My actual Coding Has MANY more lines.