Hi
Could someone help me with the coding for age restriction on film rentals? I have code to calculate a persons age, but I want to stop someone who chooses a film for example a 15 or 18 rated when they are below this age category.
This is the code to calculate a persons age:
Public Function getAge(ByVal varDOB As Variant, Optional ByVal varAsOf As Variant) As Variant
'Provided by Allen Browne, http://allenbrowne.com
'Purpose: Return the Age in years.
'Arguments: varDOB = Date Of Birth
' varAsOf = the date to calculate the age at, or today if missing.
'Return: Whole number of years.
Dim dtDOB As Date
Dim dtAsOf As Date
Dim dtBDay As Date 'Birthday in the year of calculation.
getAge = Null 'Initialize to Null
'Validate parameters
If IsDate(varDOB) Then
dtDOB = varDOB
If Not IsDate(varAsOf) Then 'Date to calculate age from.
dtAsOf = Date
Else
dtAsOf = varAsOf
End If
If dtAsOf >= dtDOB Then 'Calculate only if it's after person was born.
dtBDay = DateSerial(Year(dtAsOf), Month(dtDOB), Day(dtDOB))
getAge = DateDiff("yyyy", dtDOB, dtAsOf) + (dtBDay > dtAsOf)
End If
End If
End Function
Could someone help me with the coding for age restriction on film rentals? I have code to calculate a persons age, but I want to stop someone who chooses a film for example a 15 or 18 rated when they are below this age category.
This is the code to calculate a persons age:
Public Function getAge(ByVal varDOB As Variant, Optional ByVal varAsOf As Variant) As Variant
'Provided by Allen Browne, http://allenbrowne.com
'Purpose: Return the Age in years.
'Arguments: varDOB = Date Of Birth
' varAsOf = the date to calculate the age at, or today if missing.
'Return: Whole number of years.
Dim dtDOB As Date
Dim dtAsOf As Date
Dim dtBDay As Date 'Birthday in the year of calculation.
getAge = Null 'Initialize to Null
'Validate parameters
If IsDate(varDOB) Then
dtDOB = varDOB
If Not IsDate(varAsOf) Then 'Date to calculate age from.
dtAsOf = Date
Else
dtAsOf = varAsOf
End If
If dtAsOf >= dtDOB Then 'Calculate only if it's after person was born.
dtBDay = DateSerial(Year(dtAsOf), Month(dtDOB), Day(dtDOB))
getAge = DateDiff("yyyy", dtDOB, dtAsOf) + (dtBDay > dtAsOf)
End If
End If
End Function