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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disallow pressing spacebar in a textbox

Status
Not open for further replies.

pingpang

Programmer
Feb 1, 2003
22
0
0
PH
Good day to you!

I have a question, how can you disallow the user form pressing spacebar in a textbox? and another thing how can you limit a textbox input only for letters?

hoping for a reply soon. thanks!
 
Use the function "ONKEYPRESS". Everytime a user presses a key this function/Sub will be called. You can then check what key was pressed and then make the appropriate call if it is a alphanumeric key.

Hope this helps,
DJTN
 
pingpang ,
Why don't U use Key_Press or Key_Down Events. For Example:
------------------
'Code here
If KeyAscii = .... then
KeyAscii = 0
End if
'End Code
------------------
That's simple, do you think so? Ofcourse, may be you have better method.
Good Luck
KieuTV
 
Why don't You use the onChange event of the textbox?
if you put his in Textbox.text = trim(textbox.text) hitting the spacebar won't affect the text.
A copy and paste-operation would let a space in though, it kind of depends on how idiot-proof you want to build your program.
 
You will need to use the KeyPress event:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeySpace Then KeyAscii = 0
End Sub [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top