Input control of entry

I have declared a text for lastname, in my entry I don't like a numbers and special characters to appear as I type the name. How can I control this?
KENTROSEAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

adityauCommented:
In the KeyPress event of the text box, enter the following code.

If Not (KeyAscii >= vbKeyA And KeyAscii <= vbKeyZ) And Not (KeyAscii >= 97 And KeyAscii <= 122) And KeyAscii <> vbKeyBack Then  
    KeyAscii = 0
End If
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
caraf_gCommented:
<and a user comes along who copies rubbish in and pastes it into the text box with the mouse>
0
adityauCommented:
caraf_g, he is just asking for validation when he types. If he wants to validate when copy, paste etc., he has to handle the text box change event or else disable the option by subclassing.

Kentrose, did my answer solve my problem?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

caraf_gCommented:
No worries: I suppose it depends on how foolproof you want this to be. It's up to KENTROSE to let us know more. (And increase the number of points to something more reasonable <g>)
0
SiM99Commented:
put the code into the _change event of the textbox, rather than the keypress event....

either check the ascii value of all of the characters in the string (textbox.text) or just check the ascii value of the last character typed (right$(textbox.text)) to see if it's different to those ascii values of A-Z and a-z, if so, then either remove that character or change it.
0
BMMMAILCommented:
Kentrose might increase the points for this question.
0
KENTROSEAuthor Commented:
Thanks for the answer, it help me.
0
BMMMAILCommented:
adityau,
 I have also tried your answer in my owmn application, I add how about for the comma (,), the employee name is not separated as lastname, firstname and mi, it is just one text box. I want lastname separated by comma. There was no vbkeycomma , what is the ascii number value for this?
0
SiM99Commented:
to find the ascii value of any character, use the asc() function....

e.g. msgbox asc(",")
0
adityauCommented:
BMMMAIL

Answer is 44
0
caraf_gCommented:
This is a question that, in many variations, comes up regularly.

I wrote a Usercontrol that will allow you to do this sort of stuff, plus it handles all possible mouse and keyboard actions a user could try.

Interested, anyone?
0
KENTROSEAuthor Commented:
May you send me that code, it will help in my application.
0
caraf_gCommented:
Try this:
http://homepage.eircom.net/~carafa/VBSamples/VB6/SmartBox.zip

Create a new folder and extract the contents of the zip file into it.

Then open Group1.vbp

This project group contains two projects, one (PCSmartBox) will compile as an OCX, the other (Project1) is just a test project to illustrate how it works.

SmartBox takes care of all the nasty stuff with regards to handling mouse and keyboard action and any way the user may try to cut, copy or paste.

The only thing the text project needs to do is to code the CheckValue procedure.

In the example I've coded the CheckValue in such a way that the box will under no circumstances allow the letter "a" to appear in the box. Just a daft example ;-)

To allow proper numeric value, you just need to code "IsNumeric" in the box.

PS - the labels on the form in Project1 are a bit misleading. Nothing to do with numeric... But... try typing in an A in the smartbox. Then type an a in the text box, copy it and try to paste it. Shift+Ins, Ctrl+V, right-click with the mouse, it won't let you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.