Question : Make a selection based on age calculated from birth date

Hi Experts,

I've got a table called "people" in my MySQL database that has a field called "birthdate" the properties for this field are "Vchar" and the format is the european dateformat dd-mm-yyyy (or 23-05-1964).

In my PHP interface I would like to give the user two selection boxes where he can pick two ages running from from 6 to 16 jears old and on submit the query should show only people that match that condition.

Can this be done?  And how should I do this?

The functionality is for an interface that makes it possible to select youth members based on theire age and move them into a team.

Thanks,

Answer : Make a selection based on age calculated from birth date

Assuming that all the fields that the user could select from in each of these tables are text, try:

strApply = "[" & strField & "] = """ & strFilter & """"

If all of the fields that could be selected are not text, then you are going to have to figure out a way to determine the datatype of the field before creating strApply.  You could use a function like the following:

Public Function FieldType(TableName As String, Fieldname As String) As Integer

    Dim strSQL As String
    Dim rs As DAO.Recordset
   
    strSQL = "SELECT [" & Fieldname & "] FROM [" & TableName & "] WHERE False"
    strSQL = Replace(Replace(strSQL, "[[", "["), "]]", "]")
   
    Set rs = CurrentDb.OpenRecordset(strSQL, , dbfailonerror)
   
    FieldType = rs.Fields(0).Type
    rs.Close
    Set rs = Nothing
   
End Function

And then do something like:

intFieldType = FieldType(strReport, strField)
SELECT Case intFieldType
    Case dbBigInt, dbBoolean, dbByte, cbCurrency, dbDecimal, dbDouble, dbFload, dbInteger, dbLong, dbNumeric
        strApply = "[" & strField & "] = " & strFilter
    Case dbChar, cbText, dbMemo
        strApply = "[" & strField & "] = """ & strFilter & """"
    Case dbDate, dbTime
        strApply = "[" & strField & "] = #" & strFilter & "#"
    Case Else
        msgbox "Unexpected data type = " & intFieldType
        'This one should include all values
        strApply = ""
End Select

me.subReport.Report.Filter = strApply
me.subReport.Report.FilterOn = (strApply <> "")
Random Solutions  
 
programming4us programming4us