View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
Zak Zak is offline
external usenet poster
 
Posts: 144
Default Validation on text input boxes on a form

Hi

Thanks for helping me out with this code. I actually have created a
userform with a text input box (which is called PropDate). When the input
box pops up and the date gets entered in the correct format - how can i add
that date into the PropDate text input box on my userform?

"Rick Rothstein" wrote:

This is another possibility...

Sub ordinate()
Dim x As String
x = Application.InputBox(prompt:="enter date mm/dd/yy", Type:=2)
If x Like "##/##/##" And IsDate(x) Then
MsgBox DateValue(x)
Else
MsgBox "bad input"
End If
End Sub

--
Rick (MVP - Excel)


"Gary''s Student" wrote in message
...
Get the date as a String, and then detailed checks can be made:

Sub ordinate()
Dim x As String
Dim n As Integer
Dim dt As Date
x = Application.InputBox(prompt:="enter date mm/dd/yy", Type:=2)

If Len(x) < 8 Then
MsgBox ("bad input")
End If

s = Split(x, "/")
If UBound(s) < 2 Then
MsgBox ("bad input")
End If

n = s(0)
If n 12 Then
MsgBox ("bad input")
End If

n = s(1)
If n 31 Then
MsgBox ("bad input")
End If

dt = DateValue(x)
MsgBox (dt)
End Sub

--
Gary''s Student - gsnu200826


"zak" wrote:

Hi

I was wondering if anyone can let me know how to add validation to text
input boxes on forms?

I have several forms on a spreadsheet that I am creating and there are
quite
a few time and date input boxes, which I was hoping I could add
validation to
so that the information is entered in the correct format? i.e. date
should
only be in dd/mm/yy, time should only be entered like hh:mm etc.

Can this be done?