Validate User Input in Dialog box

D

Dee Sperling

I'm using the following to prompt the user for the starting 5 digit code in a
list.

StartingNum = Application.InputBox("Enter the 5 digit number", "Enter
Starting Number (5 digits only)")

Once I get the value, I put it in the approprate cell, increment it by one,
and keep cascading to the cells below, based on a value in another cell on
the same row, different column.

This works great, but I was wondering if there was a way to
1) Prevent the user from canceling out of the Input box.
2) Validate the input value so that if the user enters other than exactly 5
digits, it will generate an info box and force them to re-input.
3) Not error out if a letter is entered in the box. The user knows that
they are only supposed to enter digits, but if they do a typo, it goes to
Debug, and it would be better if the program would simply dicard the value
and present the input box again.

Thanks for any suggestions,
Dee
 
P

p45cal

Dee said:
I'm using the following to prompt the user for the starting 5 digit cod
in a
list.

StartingNum = Application.InputBox("Enter the 5 digit number", "Enter
Starting Number (5 digits only)")

Once I get the value, I put it in the approprate cell, increment it b
one,
and keep cascading to the cells below, based on a value in another cel
on
the same row, different column.

This works great, but I was wondering if there was a way to
1) Prevent the user from canceling out of the Input box.
2) Validate the input value so that if the user enters other tha
exactly 5
digits, it will generate an info box and force them to re-input.
3) Not error out if a letter is entered in the box. The user know
that
they are only supposed to enter digits, but if they do a typo, it goe
to
Debug, and it would be better if the program would simply dicard th
value
and present the input box again.

Thanks for any suggestions,
Dee

Do
StartingNum = Application.InputBox("Enter the 5 digit number", "Ente
Starting Number (5 digits only)", Type:=1)
If Len(StartingNum) <> 5 Then MsgBox "5 digits please!"
'If StartingNum = "False" Then MsgBox "tee hee"
Loop Until Len(StartingNum) = 5 And StartingNum <> "False
 
M

Mike H

Hi,

You could try this

Sub GetNum()
Dim Flag As Boolean
Flag = False
Dim StartingNum As Long
Do
On Error Resume Next
StartingNum = InputBox("Enter the 5 digit number", _
"Enter Starting Number (5 digits only)")
If IsNumeric(StartingNum) And StartingNum >= 10000 Then
Flag = True
Else
MsgBox "The only valid input is a 5 digit number"
End If
Loop Until Flag = True

End Sub

Mike
 
P

p45cal

p45cal;505395 said:
Do
StartingNum = Application.InputBox("Enter the 5 digit number", "Ente
Starting Number (5 digits only)", Type:=1)
If Len(StartingNum) <> 5 Then MsgBox "5 digits please!"
'If StartingNum = "False" Then MsgBox "tee hee"
Loop Until Len(StartingNum) = 5 And StartingNum <> "False"

Actually, this may fall over if the numbers can begin with a zero(s)
can they
 
D

Dee Sperling

This lets me enter 5 or more digits, but does what's needed if the entry is
non-numeric or shorter than 5 digits.

Dee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top