Age Exclusion: Help With Query Criteria

floridaboy2004

New Member
Joined
Nov 17, 2004
Messages
44
Hello,

I am in desperate need of some help in writing the Query Criteria to eliminate all customers in a table that are under the age of 18 years old on the day that they made a purchase (due to legal reasons).

How could I write a Query Criteria with the following 2 fields in my table/form?

1) DOB (Date of Birth)
2) Date of Purchase

I need to somehow write a criteria to calculate age and exclude all customers UNDER 18 years old.

Thank-you in advance for your help. :)
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
You can create a user defined function to calculate the age. Here is one that I wrote:
Code:
Function Age(Date1 As Date, Date2 As Date)
'   Calculates age between Date1 and Date2, where Date2 is the more recent date

    Dim TempAge As Long
    TempAge = Year(Date2) - Year(Date1)
    Select Case Month(Date2) - Month(Date1)
        Case Is < 0
            TempAge = TempAge - 1
        Case Is = 0
            If Day(Date2) < Day(Date1) Then TempAge = TempAge - 1
    End Select
    
    Age = TempAge

End Function
Create a new module, and paste the code above in that module. Then you can use that function in your query calculation.

So in your query, now create a new calculated field that uses this function. Something like:
CalcAge: Age([MyTable]![DOB],[MyTable]![Date of Purchase])

This should return the age. Then simply put criteria on this age to exclude anyone under 18, i.e.
>=18
 
Upvote 0

Forum statistics

Threads
1,221,831
Messages
6,162,248
Members
451,756
Latest member
tommyw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top