Reputation: 1
Got a textbox in VBA and dont want the usser to be able to type spaces in it can i prevent the usser from doing this with programing?
Upvotes: 0
Views: 7626
Reputation: 15055
' Disable Space in TextBox
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 32 Then
KeyAscii = 0
End If
End Sub
http://www.vbforums.com/showthread.php?t=447978
From google :D
Upvotes: 1
Reputation: 2236
Maybe this will help you:
You can allow/disallow specific buttons in the KeyPress-Event
Private Sub TextBox1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case asc("0") To asc("9"), 8, 32, asc(",")
'allow signs
Case Else
KeyAscii = 0 'forbid everything else
End Select
End Sub
NOTE: This example allows only numbers to be entered. You need to adapt it for your case.
Here is another page with nearly the same example but in english: LINK
Upvotes: 0