Roger Hardy
asked on
Restricting text box entry from \/:?<>"|
There's gotta be an easier way to code this...and get the " part to work, too:
Private Sub txtDocTitle_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case Asc("\")
GoTo NotAllowed:
Case Asc("/")
GoTo NotAllowed:
Case Asc(":")
GoTo NotAllowed:
Case Asc("?")
GoTo NotAllowed:
Case Asc("<")
GoTo NotAllowed:
Case Asc(">")
GoTo NotAllowed:
'case asc(""")
'GoTo NotAllowed:
Case Else
End Select
Exit Sub
NotAllowed:
strAlerts = "\ / : ? < > " & Chr(34) & " are not allowed in the title."
Call AlertsCaption_(strAlerts)
KeyAscii = 0
End Sub
ASKER
The apostrophies are there to comment-out what was erroring out. I get an error when trying to write the code.
Compile error:
Expected: list separator or )
Turns the Case Asc(""") line red.
Figured the """ was incorrect.
Compile error:
Expected: list separator or )
Turns the Case Asc(""") line red.
Figured the """ was incorrect.
You need to double up the double quotes character that is part of the string data:
Case Asc("""")
should work
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to all. Perfect!
Pleased to help
You're welcome Roger! Glad to help.
The only improvement I can see is that you can eliminate the "Case Else" as it's empty.
Also if you want to forbid the " character you should just delete the comments: remove the apostrophe there is at the beginning of the 'case asc("""") and also remove the apostrophe there is at the beginning of the next line.
So the code become like this:
Open in new window
Hope it helps. Regards