Date validation (1 Viewer)

anto.danny

Registered User.
Local time
Today, 13:59
Joined
Nov 8, 2015
Messages
35
Hello,

I want a vba code that checks the date and if the date is below 1-1-1990 then it should open a form. I know a bit of vba but I cant figure out how to enter the date in vba

Code:
If me.dateofbirth < 1-1-1990 then
DoCmd.OpenForm "helloworld"
end if

Also which event should I put the code in, so that the form opens as soon as the user goes to the next textbox?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:59
Joined
May 7, 2009
Messages
19,169
after update event of your control.
 

anto.danny

Registered User.
Local time
Today, 13:59
Joined
Nov 8, 2015
Messages
35
after update event of your control.
Its on the lost focus event of the dateofbirth textbox, but the code doesn't work when I enter a date below the year 1990. Is there a format I need to follow to use a specific date???
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:59
Joined
May 7, 2009
Messages
19,169
try casting your date constant with #:

If me.dateofbirth < #1-1-1990# then
DoCmd.OpenForm "helloworld"
end if
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:59
Joined
May 7, 2009
Messages
19,169
happy coding!
 

Users who are viewing this thread

Top Bottom