Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prohibit Special Characters in textboxes

Status
Not open for further replies.

mwheads

Programmer
Apr 24, 2004
38
ZA
Hi Everyone

I would like to prohibit my users from capturing special characters in textboxes (afterupdate)?? especially(',"=)
I do a lot of delimited exports to excel and the use of these characters can really corrupt my entire batch.

Thanks in advance
Paul
South Africa
 
You might want to consider using the KeyPress event for that textbox, trap those keys that you won't allow, and prevent their entry into the textbox.
Code:
Private Sub txtObjName_KeyPress(KeyAscii As Integer)

   Select Case KeyAscii
      Case 32, 33, 34, 35, 36 [COLOR=green white]' This is a list of the ASCII Values of those keys which you want to discard and not allow into the textbox[/color]
         KeyAscii = 0
   End Select
   
End Sub

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thanks CajunCenturion, I will give it a go when I get back to work on Monday, thanks for your time.
Out of interest, what is the step, KeyAscii = 0
much appreciated,
Paul
 
KeyAscii represents the ASCII value of the key that was pressed. If "A" is pressed then KeyAscii = 65. If a Backspace was pressed, then KeyAscii = 8. The application will receive a message that a key was pressed and it will know what key was pressed by looking at this ASCII value. Using the KeyPress event, we're intercepting this message before it gets processed, and by setting KeyAscii = 0, when this message gets to the program, it will process the key whose ASCII value is 0, nothing. The effect is the keystroke is ignored.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thanks CajunCenturion, It works like a charm.
(and my users are going to get a surprise next week when I put an end to their bad habbits.)
Regards,
Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top