ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Checking for valid date (https://www.excelbanter.com/excel-programming/284045-checking-valid-date.html)

Paul M.[_3_]

Checking for valid date
 
I'm using a userform with a textbox among other things. I
want to ensure that not only does the user submit a date
in that textbox, I want to make sure it is a valid date.
If the date is invalid, I want to display a warning
message.

Thanks for the help.

Paul

Ron de Bruin

Checking for valid date
 
Hi Paul

You can use the exit event like this.
It will not leave the textbox untill the textbox is a date

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsDate(TextBox1.Text) Then
MsgBox "not a date"
Cancel = True
End If
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Paul M." wrote in message ...
I'm using a userform with a textbox among other things. I
want to ensure that not only does the user submit a date
in that textbox, I want to make sure it is a valid date.
If the date is invalid, I want to display a warning
message.

Thanks for the help.

Paul




Tom Ogilvy

Checking for valid date
 
Look at the Isdate function.

Use the exit event for validating the textbox and also use the event code
for the buttons you are using to close the userform.

--
Regards,
Tom Ogilvy

"Paul M." wrote in message
...
I'm using a userform with a textbox among other things. I
want to ensure that not only does the user submit a date
in that textbox, I want to make sure it is a valid date.
If the date is invalid, I want to display a warning
message.

Thanks for the help.

Paul




Paul M.[_3_]

Checking for valid date
 
Fantastic !!!...Thanks Ron and Tom, it works like a dream.
-----Original Message-----
Hi Paul

You can use the exit event like this.
It will not leave the textbox untill the textbox is a date

Private Sub TextBox1_Exit(ByVal Cancel As

MSForms.ReturnBoolean)
If Not IsDate(TextBox1.Text) Then
MsgBox "not a date"
Cancel = True
End If
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Paul M." wrote in

message ...
I'm using a userform with a textbox among other things.

I
want to ensure that not only does the user submit a date
in that textbox, I want to make sure it is a valid date.
If the date is invalid, I want to display a warning
message.

Thanks for the help.

Paul



.


Bob Phillips[_6_]

Checking for valid date
 
Paul,

Here is one approach

If IsDate(Me.TextBox1.Text) Then
'do your stuff
Else
MsgBox "That's not a date"
Me.TextBox1.SetFocus
End If

Be careful though, dates are riddled with international issues. For
instance, I am in the UK, and if I enter 12/16/2003 which is really invalid,
it treats it as 16/12/2003 and is valid.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Paul M." wrote in message
...
I'm using a userform with a textbox among other things. I
want to ensure that not only does the user submit a date
in that textbox, I want to make sure it is a valid date.
If the date is invalid, I want to display a warning
message.

Thanks for the help.

Paul





All times are GMT +1. The time now is 03:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com