473,626 Members | 3,353 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

School Leaving Date - depending on age between dates

7 New Member
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 1942
ADezii
8,834 Recognized Expert Expert
Just subscribing, I'll return later and see what I can come up with.
Nov 12 '08 #2
ADezii
8,834 Recognized Expert Expert
Here is the general idea, assuming youo have a Text Box named txtEligibleToLe ave 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 New Member
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 Recognized Expert Expert
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 New Member
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 New Member
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 Recognized Expert Expert
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 Recognized Expert Expert
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 New Member
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

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

Similar topics

2
5209
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 appreciated. TIA
0
1720
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 date/tempi Si deve specificare come si vuole la differenza tra le due date/tempi fornendo annno (y), mese (m), giorno (d), ora (h), minuto (n), secondo (s). Esempio: ?Diff2Dates("y", #06/01/1998#, #06/26/2002#)
3
9803
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 table with such attributes as ID, FNAME, SNAME, Age, Tutor Group, Class, Dependant. The bit i'm having trouble conceptualising is the system needs to be
7
3054
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 need to display the date only, not the time. But I don't want to change the datatype in the database because the time is used in other places. So what I am doing is pulling it out of the database, then modifying it in ASP/VBScript by using the...
5
3157
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 tables in it. One of my forms has two TEXT BOX controls formated as Short Date. The form is binded to a linked table. The linked tables has about 7 records and one of the control is binded to a table field. These two controls displays the date...
6
1554
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 does a ton of heavy calculational lifting (for which numpy and psyco are a blessing) besides converting dates, it still seems to like to linger in the datetime and time libraries. (Maybe there's a hot module in there with a cute little function...
30
5690
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 database I have a table with Date/time column. The database is located on a machine that is set to dd/mm/yyyy also. When I enter date 7/1/08 (as in January 7, 2008), it stores it in the database as 1/7/08 instead of 7/1/08. Why is it like that...
0
16488
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 formatting considerations at all. They are simple, easy, and brief and you should use them any time you need to incorporate any date literals or date math in your T-SQL code. create function DateOnly(@DateTime DateTime) -- Returns @DateTime...
5
1634
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 database structure which works, crudely, but I'd like to re-fine it, if possible, so feel free to give your 2-pence on my design effort My 'journal' is actually a time-table for an educational establishment. It relates to my lessons over the week,...
0
8265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2625
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1808
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.