Yodelayheewho
Member
Hello all!
I have the following code for formatting textboxes as dates. I like it because if someone enters the wrong format, a message pops up and the textbox turns yellow.
However, if the user 'decides' to delete the 'bad' entry and leave the textbox blank, the code will not allow them to leave the textbox blank and move to the next field. It forces them to fill in a date.
How can the code be improved to allow the user the option to leave the date blank? Maybe add a message that says: "Are you sure you want to leave this field blank?" Yes/No and if they select "Yes" allow them to skip, "No" then it loops back to the message "Please enter a date. Ex. 12/31/2022".
Thank you in advance!
I have the following code for formatting textboxes as dates. I like it because if someone enters the wrong format, a message pops up and the textbox turns yellow.
However, if the user 'decides' to delete the 'bad' entry and leave the textbox blank, the code will not allow them to leave the textbox blank and move to the next field. It forces them to fill in a date.
How can the code be improved to allow the user the option to leave the date blank? Maybe add a message that says: "Are you sure you want to leave this field blank?" Yes/No and if they select "Yes" allow them to skip, "No" then it loops back to the message "Please enter a date. Ex. 12/31/2022".
Thank you in advance!
Code:
'***Date Format Stage Due***
Private Sub TextStageDue_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
With TextStageDue
If IsDate(TextStageDue.Text) Then
TextStageDue.Text = Format(DateValue(TextStageDue.Text), "mm/dd/yyyy")
.BackColor = vbWhite
Else
MsgBox "Please enter a date. Ex. 12/31/2022"
.BackColor = vbYellow
Cancel = True
End If
End With
End Sub