A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Calculate current school grade level



 
 
Thread Tools Display Modes
  #1  
Old April 12th, 2008, 05:04 PM posted to microsoft.public.access.forms
Ralph
external usenet poster
 
Posts: 128
Default Calculate current school grade level

I want to create a field on a form that will look at the child's birthdate
and calculate their school year (kindergarten through 12) based on their age
as of September of the current year. Example, today is April 11, 2008, I
would like the grade to be as of September 1, 2007.

Something like: If today is (whatever the date) then September 1 of the
prior year, minus the students birthdate = an integer rounded down, then 5 =
Kindergarten, 6 = first grade, 7 = second grade, etc., up to 12th grade.

Thank you in advance for any help.

Ralph
  #2  
Old April 13th, 2008, 11:27 PM posted to microsoft.public.access.forms
Wolfgang Kais[_3_]
external usenet poster
 
Posts: 68
Default Calculate current school grade level

Hello Ralph.

Ralph wrote:
I want to create a field on a form that will look at the child's
birthdate and calculate their school year (kindergarten through 12)
based on their age as of September of the current year. Example,
today is April 11, 2008, I would like the grade to be as of
September 1, 2007.

Something like: If today is (whatever the date) then September 1
of the prior year, minus the students birthdate = an integer
rounded down, then 5 = Kindergarten, 6 = first grade, 7 = second
grade, etc., up to 12th grade.


You could use a function like this (in a standard module):

Option Compare Database
Option Explicit

Function SchoolYear(Birthdate As Date) As String

Dim September1st As Date, Today As Date
Dim Birthday As Date
Dim AgeOnSeptember1st As Integer

Today = Date
September1st = DateSerial(Year(Today), 9, 1)
If September1st Today Then
September1st = DateAdd("yyyy", -1, September1st)
End If
AgeOnSeptember1st = DateDiff("yyyy", Birthdate, September1st)
Birthday = DateAdd("yyyy", AgeOnSeptember1st, Birthdate)
If Birthday September1st Then
AgeOnSeptember1st = AgeOnSeptember1st - 1
End If
Select Case AgeOnSeptember1st
Case Is 5
SchoolYear = "too young for school"
Case 5
SchoolYear = "Kindergarten"
Case 6
SchoolYear = "first grade"
Case 7
SchoolYear = "second grade"
Case 8
SchoolYear = "third grade"
Case 9 To 17
SchoolYear = CStr(AgeOnSeptember1st - 5) & "th grade"
Case Else
SchoolYear = "too old for school"
End Select

End Function

--
Regards,
Wolfgang


  #3  
Old April 13th, 2008, 11:27 PM posted to microsoft.public.access.forms
Ken Snell \(MVP\)
external usenet poster
 
Posts: 2,506
Default Calculate current school grade level

You could use an expression similar to this as the Control Source for a
textbox on the form (I'm using generic name for BirthDate field, which I
assume is in the form's Record Source query):

=DateDiff("yyyy",[BirthDate],DateSerial(Year(Date())+(Format(Date(),"mmdd")"0 901"),9,1))-5

You will get a 0 from the above expression for Kindergarten grade. If you
want to show Kindergarten as the grade in that situation, use the text box's
Format property:
;;"Kindergarten"

--

Ken Snell
MS ACCESS MVP


"Ralph" wrote in message
news
I want to create a field on a form that will look at the child's birthdate
and calculate their school year (kindergarten through 12) based on their
age
as of September of the current year. Example, today is April 11, 2008, I
would like the grade to be as of September 1, 2007.

Something like: If today is (whatever the date) then September 1 of the
prior year, minus the students birthdate = an integer rounded down, then 5
=
Kindergarten, 6 = first grade, 7 = second grade, etc., up to 12th grade.

Thank you in advance for any help.

Ralph



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:50 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.