A family of Microsoft relational database management systems designed for ease of use.
Instead of the standard SQL CASE expression call the VBA IIF function:
SELECT SUM(IIF([Leeftijd] < 18,1,0)) AS [Under 18],
SUM(IIF([Leeftijd] BETWEEN 18 AND 35,1,0)) AS [18-35]
FROM [Sheet1 Query];
Is the Leeftijd colum a computed column retuned by the Sheet1 Query query, or is it a column in a base table? If the latter the values will of course become incorrect over time unless the age is intended to be that at a specific point in time rather than the current age. The latter is best returned by computing the age on the basis of the person's date of birth, using a function such as that below:
Public Function GetAge(varDoB As Variant, Optional varAgeAt As Variant) As Variant
If IsMissing(varAgeAt) Then varAgeAt = VBA.Date
GetAge = DateDiff("yyyy", varDoB, varAgeAt) - _
IIf(Format(varAgeAt, "mmdd") < Format(varDoB, "mmdd"), 1, 0)
End Function
By default this returns the age in years at the current date, but can return the age at a specific date by passing the latter into the function as the optional varAgeAt argument.