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

Hema1

New member
Local time
Today, 18:03
Joined
Sep 28, 2023
Messages
23
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:

Users who are viewing this thread

Back
Top Bottom