shrivallabha
01-26-2011, 07:55 AM
I am creating a userform for Data Entry. It has many textboxes. Some of these textboxes will get Dates as their input. I want the users to fill the date in certain format. I spent a little while on searching and googling. Then came to this code. Is it the correct approach? Or there can be a better programming choice.
Private Sub AFCActID_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If AFCActID.Value <> "" Then
If AFCActID.Value Like "#*?#*?####" Then
Else
MsgBox "Please fill date in mm/dd/yyyy format only!"
AFCActID.Value = ""
End If
End If
End Sub
The user can choose to leave a blank field but should not enter some other info such as text.
The problem as I see: the user can get away with entering absurd info at *(asterisk). And making it:
"##?##?####"
will force the user to enter 05/05/2010 for 5/5/2010. Fat fingers won't like that. Kindly advice.
Private Sub AFCActID_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If AFCActID.Value <> "" Then
If AFCActID.Value Like "#*?#*?####" Then
Else
MsgBox "Please fill date in mm/dd/yyyy format only!"
AFCActID.Value = ""
End If
End If
End Sub
The user can choose to leave a blank field but should not enter some other info such as text.
The problem as I see: the user can get away with entering absurd info at *(asterisk). And making it:
"##?##?####"
will force the user to enter 05/05/2010 for 5/5/2010. Fat fingers won't like that. Kindly advice.