convert age to date of birth in three fields: year, month, and day. (1 Viewer)

Hema1

New member
Joined
Sep 28, 2023
Messages
22
i want if i writie the date of birth, it is converted to age in three fields: year, month, and day.
and if i write the age, it turns into the date of birth ,finally age is collected in another field
There is an update button, so that if the patient comes after a period of time, the new age is calculated using the update button.
 

Attachments

If your storing the date of birth, there is no reason to store the age, month, day, or year values. You calculate them on demand. No need for an update button. To get the month, day, or year values you would use the Month(), Day(), and Year() functions on the DOB. For the age you'd use a function like the one DBguy provided.

If you just want Age in years you could use something like:
Code:
Public Function fYearsOld(ByVal dteDate As Date) As Integer

    On Error GoTo fYearsOld_Error
    
    Dim intYears As Integer
  
    intYears = Year(Now) - Year(dteDate)
  
    If DateSerial(Year(Now), Month(dteDate), Day(dteDate)) > Now Then
        intYears = intYears - 1
    End If
 
    fYearsOld = intYears
    
    On Error GoTo 0
    Exit Function

fYearsOld_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure fYearsOld, line " & Erl & "."

End Function
 
Last edited:
There is an update button, so that if the patient comes after a period of time, the new age is calculated using the update button.
Once you convert the existing ages to dates, you should remove age from the table and just leave the date. Make everyone born on Jan 1 for the conversion. Then calculate the age on the fly in a query rather than storing it because if you store the date, it could be invalid tomorrow so it will always be suspect. Why keep suspect data?
 

Users who are viewing this thread

Top Bottom