• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro to restrict user to enter double quotes in text box

Dhamo

New Member
Hi,


This is my code.


Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

Select Case KeyAscii

Case Asc(":"), Asc("?"), Asc("*"), Asc("<"), Asc(">"), Asc(""), Asc("/"), Asc("|") ', Asc(""")

KeyAscii = 0

End Select

End Sub


If I uncomment for ", I am getting error. I need to fix this. I tried Chr(34) also. But vain. Pls help.
 
You need to add one more quote like this:

[pre]
Code:
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case Asc(":"), Asc("?"), Asc("*"), Asc("<"), Asc(">"), Asc(""), Asc("/"), Asc("|"), Asc("""")
KeyAscii = 0
End Select
End Sub
and also try chr(34) as below:

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case Asc(":"), Asc("?"), Asc("*"), Asc("<"), Asc(">"), Asc(""), Asc("/"), Asc("|"), Asc(Chr(34))
KeyAscii = 0
End Select
End Sub
[/pre]
 
Back
Top