Hi,
I have to setup database and also design a registration form for the customer. So I created Customer table and there is a field called "Date of Birth" I'm just wondering if I can enter a validation rule for the "Date of Birth" field which only allows people over 18 years old.
Please someone tell me what the validation rule is and I'm using Access 2007.
Thanks!
Loading
Sushobhan ChakrabortyPosted Nov 1, 2010, 7:24 AM
Set the MinimumValue of the Validator as follows
RangeValidator1.MinimumValue = (new DateTime(DateTime.Now.Year-18,DateTime.Now.Month,DateTime.Now.Day)).ToShortDateString();
ShankeyPosted Nov 1, 2010, 7:08 AM
You can write custom validator. In the function called by custom validator you can find the difference between the date of birth and todays date. Please mark my answer as accepted if it helped you
Thanks,
Maninder
Manikavelu VelayuthamPosted Nov 10, 2010, 2:35 AM
DECLARE @CurrentDate DATETIME
SELECT @CurrentDate = '20070210', @BirthDate = '19790519'
SELECT
DATEDIFF(YY, @BirthDate, @CurrentDate) -
CASE
WHEN(
(MONTH(@BirthDate)*100 + DAY(@BirthDate)) >
(MONTH(@CurrentDate)*100 + DAY(@CurrentDate))
) THEN 1
ELSE 0
END
The above script will tell you the correct age, if you pass the current date and date of birth.
you can set this as a constraint in your table.
But am not sure whether its possible in Access 2007.
In Sql Server its possible.
Just try it out and let me know