Help needed with age restriction code

sxi12345

Registered User.
Local time
Yesterday, 22:38
Joined
Mar 7, 2007
Messages
12
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
 
the function you have is called GETAGE, and will return a persons age

you just call this by

customerage = getage(hisbirthdate)

that will give his age in years relative to today

if you want it relative to another date just use

customerage = getage(hisbirthdate,#1/1/2007#)
 
I know this, i just want some validation to stop someone renting a film who is not old enough to for a certain film category, e.g 18,15,12 etc
 
well all yuo need is a case statemment or an if statement

select case filmclass

case "15plus": if customerage(hisbirthday)<15 then etc

case "AdultsOnly": if customerage(hisbirthday)<18 then etc

end select
 
ok thank you I will try that. Do you have email so I can contact you if I have some problems?
 
ok thank you I will try that. Do you have email so I can contact you if I have some problems?
The forum is here so everyone can benefit when problems are solved. It is considered bad form to request personal attention unless you want to pay an hourly fee. Even then, only when it is suggested by the person helping which is rarely done and discouraged by the forum.
 

Users who are viewing this thread

Back
Top Bottom