Hello,
I have this code that prevents the user to enter the incorrect date format. I am wondering if it is possible for the textbox to accept "N/A". Meaning that if the user enters N/A to textbox19 the message box still shows "Date format is not correct" and the back color as yellow but it allows the user to keep using the form (as if Cancel = False) but only when "N/A" is entered on textbox19. When the date is not entered in the specified format on the code then it should work the same all the same, showing the message "Date format is not correct", the back color in yellow and not allowing to keep using the form (Cancel = True). Can I please have your help with this? Thank you.
I have this code that prevents the user to enter the incorrect date format. I am wondering if it is possible for the textbox to accept "N/A". Meaning that if the user enters N/A to textbox19 the message box still shows "Date format is not correct" and the back color as yellow but it allows the user to keep using the form (as if Cancel = False) but only when "N/A" is entered on textbox19. When the date is not entered in the specified format on the code then it should work the same all the same, showing the message "Date format is not correct", the back color in yellow and not allowing to keep using the form (Cancel = True). Can I please have your help with this? Thank you.
VBA Code:
Private Sub TextBox19_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
With TextBox19
If IsDate(.Text) Then
.Text = Format(DateValue(.Text), "mm/dd/yyyy")
.BackColor = vbWhite
Else
MsgBox "Date format is not correct"
.BackColor = vbYellow
Cancel = True
End If
End With
End Sub