473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

School Leaving Date - depending on age between dates

7
I have an access database (MS Access 2002,) which stores school pupils information and I have very limited knowledge on VBA. Hopefully someone can help solve this one for me.


I have a form named frmPupils which contains the Date of Birth (field name - DOB).

I want to add a textbox to the form which will display a date that the pupil is
elegible to leave school, which is dependant on what is entered in the DOB field.


There are two possible school leaving dates in the year.
31st May and 31st December.

If a pupil's 16th birthday is on or between 1st March and 30th September
they can leave school on 31st May of that year.

If a pupil's 16th birthday is on or between 1st October until end of February,
28th or 29th if it's a leap year!
Then they can leave school on 31st December.

eg. If DOB = 16th August 1992, their 16th birthday is in August 2008,
(within the period between 1st March to 30th September),
so they can leave school on 31st May 2008.

If DOB = 16th February 1993, their 16th birthday will be in February 2009,
(within the period between 1st October to end of February),
so they can leave school on 31st December 2008.


Any help would be much appreciated.
Nov 12 '08 #1
10 1922
ADezii
8,834 Expert 8TB
Just subscribing, I'll return later and see what I can come up with.
Nov 12 '08 #2
ADezii
8,834 Expert 8TB
Here is the general idea, assuming youo have a Text Box named txtEligibleToLeave on the Form:
Expand|Select|Wrap|Line Numbers
  1. Dim dte16thBirthday As Date
  2.  
  3. 'Must contain some Value and it must be a Date
  4. If IsNull(Me![DOB]) Or Not IsDate(Me![DOB]) Then Exit Sub
  5.  
  6. dte16thBirthday = DateAdd("yyyy", 16, CDate(Me![DOB]))
  7.  
  8. If dte16thBirthday >= #3/1/2008# And dte16thBirthday <= #9/30/2008# Then
  9.   Me![txtEligibleToLeave] = "5/31/2008"
  10. ElseIf dte16thBirthday >= #10/1/2008# And dte16thBirthday <= #2/28/2009# Then
  11.   Me![txtEligibleToLeave] = "12/31/2008"
  12. Else
  13.   'not sure what you want to do here
  14. End If
Nov 12 '08 #3
JacD
7
Thank you for your input and quick response.

I need it to be able to show leaving dates no matter what age they are at present.

So even if their DOB is 10th February 2000 (currently aged 8), I want it to show their expected leaving date in years to come when they do reach 16 between the dates mentioned, if that makes sense.

DOB = 10th February 2000
Expected Leaving Date to show as - 31st December 2015

or

DOB = 7th September 2002
Expected Leaving Date to show as - 31st May 2018

Hope you can help again. Thanks in advance
Nov 12 '08 #4
ADezii
8,834 Expert 8TB
Assuming you have 2 Text Boxes named txtDOB (Date of Birth), and txtEligible (to receive the Eligibility Date), place the following code in the AfterUpdate() Event of txtDOB and let me know if it produced the requested results:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtDOB_AfterUpdate()
  2. Dim dte16th As Date
  3.  
  4. 'Must contain some Value and it must be a Date
  5. If IsNull(Me![txtDOB]) Or Not IsDate(Me![txtDOB]) Then Exit Sub
  6.  
  7. dte16th = DateAdd("yyyy", 16, CDate(Me![txtDOB]))
  8.  
  9. If dte16th >= DateSerial(Year(dte16th), 3, 1) And _
  10.    dte16th <= DateSerial(Year(dte16th), 9, 30) Then
  11.   Me![txtEligible] = DateSerial(Year(dte16th), 5, 31)
  12. Else
  13.   Me![txtEligible] = DateSerial(Year(dte16th) - 1, 12, 31)
  14. End If
  15. End Sub
Nov 13 '08 #5
JacD
7
Your almost there, it's looking very promising though. It's working fine for pupils who leave on 31st May.

The problem is with the December leaving date -

Else
Me![txtEligible] = DateSerial(Year(dte16th) - 1, 12, 31)


It needs split up further as only those with a birthday between 1st Jan and 29th Feb would be allowed to leave the year before they are 16 years old (on 31st December)

eg. Aged 16 on 5th February 2008, a pupil can leave on 31st Dec 2007.

And those aged 16 between 1st October 2007 and 31st Dec 2007 could leave on 31st Dec 2007, which I guess would look like the following? (without the -1)?

Me![txtEligible] = DateSerial(Year(dte16th), 12, 31)


Leaving the code as it is is making a pupil aged 16 between Oct and Dec eligible to leave the year before they should, but is showing perfectly correct for those with a birthday between Jan and Feb. So somehow I'd need both codes to show for 31st December leavers.

The other thing I noticed, when entering a DOB, it updates the txtEligible but when scrolling to another record, it shows the same eligible date as the last record I entered a DOB? Any thoughts?

It's confusing I know! Thanks for your time. Hope you can help?
Nov 13 '08 #6
JacD
7
I managed to add a bit to your code and it is now working exactly as I need it.

Private Sub DOB_AfterUpdate()

Dim dte16th As Date

'Must contain some Value and it must be a Date
If IsNull(Me![DOB]) Or Not IsDate(Me![DOB]) Then Exit Sub

dte16th = DateAdd("yyyy", 16, CDate(Me![DOB]))

If dte16th >= DateSerial(Year(dte16th), 3, 1) And _
dte16th <= DateSerial(Year(dte16th), 9, 30) Then
Me![txtEligible] = DateSerial(Year(dte16th), 5, 31)
Else
If dte16th >= DateSerial(Year(dte16th), 10, 1) And _
dte16th <= DateSerial(Year(dte16th), 12, 31) Then
Me![txtEligible] = DateSerial(Year(dte16th), 12, 31)

Else
If dte16th >= DateSerial(Year(dte16th), 1, 1) And _
dte16th < DateSerial(Year(dte16th), 3, 1) Then
Me![txtEligible] = DateSerial(Year(dte16th) - 1, 12, 31)
End If
End If
End If

End Sub

Thanks again for all your help with this. It's very much appreciated.
Jacqueline :)
Nov 13 '08 #7
ADezii
8,834 Expert 8TB
Your almost there, it's looking very promising though. It's working fine for pupils who leave on 31st May.

The problem is with the December leaving date -

Else
Me![txtEligible] = DateSerial(Year(dte16th) - 1, 12, 31)


It needs split up further as only those with a birthday between 1st Jan and 29th Feb would be allowed to leave the year before they are 16 years old (on 31st December)

eg. Aged 16 on 5th February 2008, a pupil can leave on 31st Dec 2007.

And those aged 16 between 1st October 2007 and 31st Dec 2007 could leave on 31st Dec 2007, which I guess would look like the following? (without the -1)?

Me![txtEligible] = DateSerial(Year(dte16th), 12, 31)


Leaving the code as it is is making a pupil aged 16 between Oct and Dec eligible to leave the year before they should, but is showing perfectly correct for those with a birthday between Jan and Feb. So somehow I'd need both codes to show for 31st December leavers.

The other thing I noticed, when entering a DOB, it updates the txtEligible but when scrolling to another record, it shows the same eligible date as the last record I entered a DOB? Any thoughts?

It's confusing I know! Thanks for your time. Hope you can help?
The other thing I noticed, when entering a DOB, it updates the txtEligible but when scrolling to another record, it shows the same eligible date as the last record I entered a DOB? Any thoughts?
txtEligible is not 'Bound' to any underlying Field, namely it has no Control Source.
Nov 13 '08 #8
ADezii
8,834 Expert 8TB
I managed to add a bit to your code and it is now working exactly as I need it.

Private Sub DOB_AfterUpdate()

Dim dte16th As Date

'Must contain some Value and it must be a Date
If IsNull(Me![DOB]) Or Not IsDate(Me![DOB]) Then Exit Sub

dte16th = DateAdd("yyyy", 16, CDate(Me![DOB]))

If dte16th >= DateSerial(Year(dte16th), 3, 1) And _
dte16th <= DateSerial(Year(dte16th), 9, 30) Then
Me![txtEligible] = DateSerial(Year(dte16th), 5, 31)
Else
If dte16th >= DateSerial(Year(dte16th), 10, 1) And _
dte16th <= DateSerial(Year(dte16th), 12, 31) Then
Me![txtEligible] = DateSerial(Year(dte16th), 12, 31)

Else
If dte16th >= DateSerial(Year(dte16th), 1, 1) And _
dte16th < DateSerial(Year(dte16th), 3, 1) Then
Me![txtEligible] = DateSerial(Year(dte16th) - 1, 12, 31)
End If
End If
End If

End Sub

Thanks again for all your help with this. It's very much appreciated.
Jacqueline :)
You are quite welcome, Jacqueline and way to jump in and provide the final solution to your problem!. In the future, you may wish to incorporate Code Tags in your Code for the sake of clarity and readability as in:
Expand|Select|Wrap|Line Numbers
  1. Private Sub DOB_AfterUpdate()
  2. Dim dte16th As Date
  3.  
  4. 'Must contain some Value and it must be a Date
  5. If IsNull(Me![DOB]) Or Not IsDate(Me![DOB]) Then Exit Sub
  6.  
  7. dte16th = DateAdd("yyyy", 16, CDate(Me![DOB]))
  8.  
  9. If dte16th >= DateSerial(Year(dte16th), 3, 1) And _
  10.    dte16th <= DateSerial(Year(dte16th), 9, 30) Then
  11.      Me![txtEligible] = DateSerial(Year(dte16th), 5, 31)
  12. Else
  13.   If dte16th >= DateSerial(Year(dte16th), 10, 1) And _
  14.      dte16th <= DateSerial(Year(dte16th), 12, 31) Then
  15.        Me![txtEligible] = DateSerial(Year(dte16th), 12, 31)
  16.   Else
  17.     If dte16th >= DateSerial(Year(dte16th), 1, 1) And _
  18.       dte16th < DateSerial(Year(dte16th), 3, 1) Then
  19.       Me![txtEligible] = DateSerial(Year(dte16th) - 1, 12, 31)
  20.     End If
  21.   End If
  22. End If
  23. End Sub
Nov 13 '08 #9
JacD
7
Thanks. Looks much easier to read. That's what happens when you are more of a letter writer than a Code writer, it's hard not to left align everything!

txtEligible is not 'Bound' to any underlying Field, namely it has no Control Source.
Still puzzling how to overcome this. Had hoped that txtEligible would update in all records depending on the DOB of each record.
Nov 14 '08 #10
ADezii
8,834 Expert 8TB
Still puzzling how to overcome this. Had hoped that txtEligible would update in all records depending on the DOB of each record
Keep in mind that you would not be updating txtEligible, but the Field to which it is Bound. If you have a Field in tblPupils named [Eligible_Date] that you wish to Update based on a Field named [DOB], you would need an Update Query.
Nov 14 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
0
by: UBI | last post by:
Vorrei suggerire una funzione completa per la differenza fra due date. (questo è codice freeware, niente di illegale) La funzione seguente permette il calcolo di una differenza precisa tra due...
3
by: shahram.shirazi | last post by:
Hi guys, I was wondering if someone could help me a bit here. Im trying to desing an electronic register system for a school. In terms of the table design, I obviously need a Student Details...
7
by: Middletree | last post by:
I am trying to display dates in a spreadsheet, but the dates need to be in a format that will allow them to be sorted in Excel. The datatype in the SQL Server database is datetime. In this case, I...
5
by: Easystart | last post by:
Hi, Sorry for my English. English is not my native tougue. I am working in MS Access 2000 with a SQLServer 2000 Backend database. MS Access 2000 is my GUI front end that has SQLServer linked...
6
by: vdicarlo | last post by:
I am a programming amateur and a Python newbie who needs to convert about 100,000,000 strings of the form "1999-12-30" into ordinal dates for sorting, comparison, and calculations. Though my script...
30
by: fniles | last post by:
On my machine in the office I change the computer setting to English (UK) so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US. This problem happens in either Access or SQL Server. In the...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
5
by: thecheyenne | last post by:
Hi there and happy new year to all of you. I've been reading the thread "Auto Date in form "pages" from 'frys' in the topics and his/her problem is similar though not identical to mine. Here is my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.