Future Date Validation (1 Viewer)

majid.pervaiz

Registered User.
Local time
Today, 04:40
Joined
Oct 15, 2012
Messages
110
Dear All,

I have the below code on a field that contains a date, I don't want user to enter a future date in the field. But unfortunately, it's not working, not sure the reason.

I tried the same on lost focus event also.

appreciate your advice.

Private Sub BO_App_Date_Exit(Cancel As Integer)
If Me.BO_App_Date > Date Then

MsgBox "you cannot put future date", vbExclamation
Me.BO_App_Date.Value = ""
End If

End Sub
 

Minty

AWF VIP
Local time
Today, 02:40
Joined
Jul 26, 2013
Messages
10,371
Use the before update property

If Me.BO_App_Date > Date Then

MsgBox "you cannot put future date", vbExclamation
Cancel = True
End If
 

majid.pervaiz

Registered User.
Local time
Today, 04:40
Joined
Oct 15, 2012
Messages
110
no it didn't work... I am really shocked. I did the same thing on another form but I don't know why in specific on this form it's not working
 

majid.pervaiz

Registered User.
Local time
Today, 04:40
Joined
Oct 15, 2012
Messages
110
well I have use validation rule and validation text for now... God knows why it's not working
 

Minty

AWF VIP
Local time
Today, 02:40
Joined
Jul 26, 2013
Messages
10,371
Did you get an error, and did you remove all the other events on that control to avoid confusion ?
 

majid.pervaiz

Registered User.
Local time
Today, 04:40
Joined
Oct 15, 2012
Messages
110
Minty bro resolved - actually I overlooked one thing. I had some data existing so what was happening the date let's say is mentioned 01/01/2016 the moment I click on the calendar I was selecting 15/08/2016 and didn't notice the month... offcourse system will not then tell me it's a future date :(

apologies for inconvenience caused.

many thanks
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 11:40
Joined
Jan 20, 2009
Messages
12,852
I probably would not clear out what the user has entered, so that they can see their mistake.
 

Users who are viewing this thread

Top Bottom