We help IT Professionals succeed at work.
Get Started

InputBox, restricting special chars?

69 Views
Last Modified: 2019-12-26
Is there a way to restrict special characters, on an inputbox?  I was testing this and my mouse fell on the keyboard, adding a / character, so I went with it and oddly it made the procedure fail.  Either I need to Dim strNewListItemName as something different or add another ElseIf.  Please advise and thanks.  ( way odd to find this failure that way.  lol)

Do
        strNewListItemName = InputBox("Please enter an account name.", "Enter new account name", SampleName)
        If strNewListItemName = "New Account name." Then
            MsgBox ("You need to change the default account input")
        ElseIf StrPtr(strNewListItemName) = 0 Then
            Exit Sub
        ElseIf strNewListItemName = "" Then
            MsgBox ("Can not be blank or use the default input text")
        ElseIf Len(strNewListItemName) > 30 Then
            MSG1 = MsgBox("Your account name exceeded 30 characters, try shortening the account name.", vbOKOnly + 48, "Warning, Error")
        End If
    Loop Until Len(strNewListItemName) < 31 And Not strNewListItemName = "New Account name." And Not strNewListItemName = ""

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE