D
Debwin
I'm very new to Access but I've created a form named NewMembers which is
linked to a table called members. The object of the form is for the user to
input new membership details and besides the usual fields of name, address
etc. I have a field for Date of Birth. I also have a field called Schooldate
which contains the date of the school starting year i.e. 31/08/2006 and
another 2 unbound text boxes called Age(which shows the age of the member at
start of school year) and Session (which shows a value of 1 or 2 dependant on
whether the member was under or over 11 at the start of school date.)
I have written/obtained code to calculate the values for the age and session
fields but I need these values to be stored in the table also.
The code I have used to calculate values is below, but I am really stuck with
how to get these values into the table and would appreciate any suggestions.
Public Function GetAgeStr(varDOB As Variant, varDate As Variant) As String
' Purpose Returns a string of the age between dates in the following
format:
' Yy-Mm where Y is years and M is the months between dates
Dim dteDOB As Date, dteDate As Date
Dim lngMonths As Long, lngYears As Long
Dim value
value = GetAgeStr
If IsDate(varDOB) And IsDate(varDate) Then
dteDOB = CDate(varDOB)
dteDate = CDate(varDate)
lngMonths = DateDiff("M", dteDOB, dteDate) Mod 12
lngYears = DateDiff("M", dteDOB, dteDate) \ 12
If DatePart("m", dteDate) = DatePart("m", dteDOB) And DatePart("d", dteDate)
< DatePart("d", dteDOB) Then
lngYears = lngYears - 1
lngMonths = 11
End If
GetAgeStr = lngYears & "." & lngMonths
Else
GetAgeStr = ""
End If
End Function
Public Function GetSession() As Integer
Dim currentAge As Variant
Dim schoolAge As Double
currentAge = CDbl(txtAge)
GetSession = currentAge
schoolAge = (11#)
If currentAge < schoolAge Then
GetSession = 1
Else
If currentAge > schoolAge Then
GetSession = 2
End If
End If
linked to a table called members. The object of the form is for the user to
input new membership details and besides the usual fields of name, address
etc. I have a field for Date of Birth. I also have a field called Schooldate
which contains the date of the school starting year i.e. 31/08/2006 and
another 2 unbound text boxes called Age(which shows the age of the member at
start of school year) and Session (which shows a value of 1 or 2 dependant on
whether the member was under or over 11 at the start of school date.)
I have written/obtained code to calculate the values for the age and session
fields but I need these values to be stored in the table also.
The code I have used to calculate values is below, but I am really stuck with
how to get these values into the table and would appreciate any suggestions.
Public Function GetAgeStr(varDOB As Variant, varDate As Variant) As String
' Purpose Returns a string of the age between dates in the following
format:
' Yy-Mm where Y is years and M is the months between dates
Dim dteDOB As Date, dteDate As Date
Dim lngMonths As Long, lngYears As Long
Dim value
value = GetAgeStr
If IsDate(varDOB) And IsDate(varDate) Then
dteDOB = CDate(varDOB)
dteDate = CDate(varDate)
lngMonths = DateDiff("M", dteDOB, dteDate) Mod 12
lngYears = DateDiff("M", dteDOB, dteDate) \ 12
If DatePart("m", dteDate) = DatePart("m", dteDOB) And DatePart("d", dteDate)
< DatePart("d", dteDOB) Then
lngYears = lngYears - 1
lngMonths = 11
End If
GetAgeStr = lngYears & "." & lngMonths
Else
GetAgeStr = ""
End If
End Function
Public Function GetSession() As Integer
Dim currentAge As Variant
Dim schoolAge As Double
currentAge = CDbl(txtAge)
GetSession = currentAge
schoolAge = (11#)
If currentAge < schoolAge Then
GetSession = 1
Else
If currentAge > schoolAge Then
GetSession = 2
End If
End If