Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
I have a userform where the user will input their birthdate. I used the
IsDate function to make sure they enter a valid date. I would like to add code to catch dates that are in the future (e.g., "If txtBirthdate.Value Today Then..."). This is the code I have so far: Private Sub txtBirthdate_Exit(ByVal Cancel As MSForms.ReturnBoolean) If txtBirthdate = vbNullString Then Exit Sub If Not IsDate(txtBirthdate) Then MsgBox "That is not a valid birthdate." Cancel = True End If End Sub |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Private Sub txtBirthdate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If txtBirthdate = vbNullString Then Exit Sub If Not IsDate(txtBirthdate) Then MsgBox "That is not a valid birthdate." Cancel = True End If If txtBirthdate Date(Now()) then MsgBox "That date is in the future!" Cancel = True End If End Sub |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Private Sub txtBirthdate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If txtBirthdate = vbNullString Then Exit Sub If Not IsDate(txtBirthdate) Then MsgBox "That is not a valid birthdate." Cancel = True End If If Format(txtBirthdate, "#.00") Format(Now(), "#.00") Then MsgBox "That date is in the future!" Cancel = True End If End Sub |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi
If you are using ISDATE() then you dont need to validate Nullstring. Also use CDATE() to typecast the variable to date and compare the date with current date using DATEDIFF() function as below.. If Not IsDate(txtBirthDate) Then MsgBox "That is not a valid birthdate." : Cancel = True Else If DateDiff("d", CDate(txtBirthDate), Date) < 0 Then MsgBox "That is a future date" : Cancel = True End If End If If this post helps click Yes --------------- Jacob Skaria "Horatio J. Bilge, Jr." wrote: I have a userform where the user will input their birthdate. I used the IsDate function to make sure they enter a valid date. I would like to add code to catch dates that are in the future (e.g., "If txtBirthdate.Value Today Then..."). This is the code I have so far: Private Sub txtBirthdate_Exit(ByVal Cancel As MSForms.ReturnBoolean) If txtBirthdate = vbNullString Then Exit Sub If Not IsDate(txtBirthdate) Then MsgBox "That is not a valid birthdate." Cancel = True End If End Sub |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Check using greater than...
If Not IsDate(txtBirthDate) Then MsgBox "That is not a valid birthdate.": Cancel = True Else If CDate(txtBirthDate) Date Then MsgBox "That is a future date": Cancel = True End If End If -- If this post helps click Yes --------------- Jacob Skaria "Jacob Skaria" wrote: Hi If you are using ISDATE() then you dont need to validate Nullstring. Also use CDATE() to typecast the variable to date and compare the date with current date using DATEDIFF() function as below.. If Not IsDate(txtBirthDate) Then MsgBox "That is not a valid birthdate." : Cancel = True Else If DateDiff("d", CDate(txtBirthDate), Date) < 0 Then MsgBox "That is a future date" : Cancel = True End If End If If this post helps click Yes --------------- Jacob Skaria "Horatio J. Bilge, Jr." wrote: I have a userform where the user will input their birthdate. I used the IsDate function to make sure they enter a valid date. I would like to add code to catch dates that are in the future (e.g., "If txtBirthdate.Value Today Then..."). This is the code I have so far: Private Sub txtBirthdate_Exit(ByVal Cancel As MSForms.ReturnBoolean) If txtBirthdate = vbNullString Then Exit Sub If Not IsDate(txtBirthdate) Then MsgBox "That is not a valid birthdate." Cancel = True End If End Sub |
#6
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
That works great. Thanks.
~ Horatio "Jacob Skaria" wrote: Check using greater than... If Not IsDate(txtBirthDate) Then MsgBox "That is not a valid birthdate.": Cancel = True Else If CDate(txtBirthDate) Date Then MsgBox "That is a future date": Cancel = True End If End If -- If this post helps click Yes --------------- Jacob Skaria "Jacob Skaria" wrote: Hi If you are using ISDATE() then you dont need to validate Nullstring. Also use CDATE() to typecast the variable to date and compare the date with current date using DATEDIFF() function as below.. If Not IsDate(txtBirthDate) Then MsgBox "That is not a valid birthdate." : Cancel = True Else If DateDiff("d", CDate(txtBirthDate), Date) < 0 Then MsgBox "That is a future date" : Cancel = True End If End If If this post helps click Yes --------------- Jacob Skaria "Horatio J. Bilge, Jr." wrote: I have a userform where the user will input their birthdate. I used the IsDate function to make sure they enter a valid date. I would like to add code to catch dates that are in the future (e.g., "If txtBirthdate.Value Today Then..."). This is the code I have so far: Private Sub txtBirthdate_Exit(ByVal Cancel As MSForms.ReturnBoolean) If txtBirthdate = vbNullString Then Exit Sub If Not IsDate(txtBirthdate) Then MsgBox "That is not a valid birthdate." Cancel = True End If End Sub |
#7
![]() |
|||
|
|||
![]()
__________________
I am not human. I am an Excel Wizard |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
save as future date eg expected delivery date | Excel Discussion (Misc queries) | |||
Tricky Date calculation: How to calculate a future date | Excel Discussion (Misc queries) | |||
formula to calculate future date from date in cell plus days | Excel Worksheet Functions | |||
date in the future | New Users to Excel | |||
Calculating days between current date and a date in future NETWORKDAYS() function | Excel Worksheet Functions |