Restriction for the Date Field in UserForm

S

shahzad4u_ksa

I have a UserForm and I put the restriction on the "DatePurchase"
textbox. so user can not skip this field. it is working fine. I used
the following code for that.


Private Sub DatePurchase_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsDate(DatePurchase) Then
MsgBox "Input must be a date in the format: 'dd/mmm/yyyy'"
Cancel = True
Else
DatePurchase = Format(DatePurchase, "dd/mmm/yyyy")
End If
End Sub



Private Sub CloseForm_Click()

Unload Me

End Sub


when I Load the UserForm and I dont want to go for entry and I want to
close this form by close button, with Unload me command. then my
userform is not going to close at all, unless I feed the Date in
"DatePurchase" Field.

when I hit the close button without feeding the Date, the Input
message is appearing. "Input must be a date in the format: 'dd/mmm/
yyyy'"

I want my Form to be close when I hit the close button


Pls give me any suggession.......

Regards.

Shahzad
 
K

Keith74

Have a look at using something other than the exit event for that
textbox, e.g. afterupdate
or put the date validation in the code for the "proceed" command
button i'm guessing you have.

hth

keith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top