My userform uses a date picker, so all dates entered in the text box "txtsumfrom" will be in (USA) short date format. I had code to allow blanks, and to ensure the value was in date format (in case they wrote over the dater picker) - but I also want to add a rule that the entered date could not be before a certain date (in this case, 7/1/14) or a future date). So I added the code highlighted below. I don't get an error (yay me, I'm learning!), but it doesn't work either!
I also need to know what code to not allow the dates. As is, it just is suppose to give the message box, but will still allow the forbidden date value. Any help is greatly appreciated!
-HeyInKyPrivate Sub txtsumfrom_Exit(ByVal Cancel As MSForms.ReturnBoolean) If txtsumfrom.Value = "" Then Exit Sub Else 'check date format If Not IsDate(txtsumfrom) Then MsgBox "Plese enter a valid date." Cancel = True If txtsumfrom.Value < "7/1/2014" Then MsgBox "You cannot enter a date before July 1, 2014." If txtsumfrom.Value > Today Then MsgBox "You cannot enter a date in the future." End If Exit Sub End If End Sub
Bookmarks