Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Just have only the one test for 12 and add a date check to your function for Class 6, then it will always return Grade 6 after that date.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  2. #17
    erickemboi is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    73
    kindly, please somebody to help with a function to delete CLASS 6 on 1ST MAY 2022. I am stuck. Please help. Update this dummy students database
    Attached Files Attached Files

  3. #18
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Function fails if school year not supplied, so hardly optional?

    Change your computer date to 1st May 2022 to test new grade.
    Test for today as well
    Code:
    Function ConvertBirthdayToGrade(Birthday As Date, Optional SchoolYear As Variant) As String
        Dim intGrade As Integer
        On Error Resume Next
        '5 YEARS -PP1
        '6 YEARS -PP2
        '7 YEARS- GRADE 1
        '8 YEARS- GRADE 2
        '9 YEARS- GRADE 3
        '10 YEARS- GRADE 4
        '11 YEARS- GRADE 5
        '12 YEARS- CLASS 6(TO BE DELETED permanently ON 1ST MAY 2022)
        '12 YEARS- GRADE 6
        '13 YEARS- CLASS 7
        '14 YEARS- CLASS 8
    
        'If IsEmpty(SchoolYear) Then SchoolYear = Format(Date, "yyyy")
    
        intGrade = CInt(Left(SchoolYear, 4)) - Year(Birthday)
    
        Select Case intGrade
        Case Is < 5
            ConvertBirthdayToGrade = "NOT YET IN SCHOOL! LEARNER STILL VERY YOUNG!"
        Case 5
            ConvertBirthdayToGrade = "PP1"
        Case 6
            ConvertBirthdayToGrade = "PP2"
        Case 7
            ConvertBirthdayToGrade = "GRADE 1"
        Case 8
            ConvertBirthdayToGrade = "GRADE 2"
        Case 9
            ConvertBirthdayToGrade = "GRADE 3"
        Case 10
            ConvertBirthdayToGrade = "GRADE 4"
        Case 11
            ConvertBirthdayToGrade = "GRADE 5"
        Case 12
            If Date < #5/1/2022# Then
                ConvertBirthdayToGrade = "CLASS 6"
            Else
                ConvertBirthdayToGrade = "GRADE 6"
            End If
        Case 13
            ConvertBirthdayToGrade = "CLASS 7"
        Case 14
            ConvertBirthdayToGrade = "CLASS 8"
        Case Is >= 15
            ConvertBirthdayToGrade = "LEARNER NO LONGER IN SCHOOL! CHECK BIRTH DATE!!"
        End Select
    
    
    End Function
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #19
    erickemboi is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    73
    You are genius. Thanks so much. God bless you. Cheers!

  5. #20
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,880
    Still not sure I follow you. your going to need to be more specific

    Deleted where? In the combobox? In the table?

    Do you want case 12 to show class6 untill 5/1/22 and then it will show Grade6 from then on?
    if thats the case you could use
    Code:
    Case 12
    ConvertBirthdayToGrade = IIf(Date < #5/1/2022#, "Class6", "Grade6")
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #21
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,880
    You appear to have your test for the missing argument commented out, so no default value is being assigned as Gasman points out.

    Rather than IsEmpty, I believe you want IsMissing.

    Also dont think you need all the formating as the year function should suffice.

    Code:
    Function ConvertBirthdayToGrade(Birthday As Date, Optional SchoolYear As Variant) As String
        Dim intGrade As Integer
        On Error Resume Next
    
    
        If IsMissing(SchoolYear) Then SchoolYear = Date
    
    
        intGrade = Year(SchoolYear) - Year(Birthday)
    
    
        Select Case intGrade
    
    
        Case Is < 5
            ConvertBirthdayToGrade = "NOT YET IN SCHOOL! LEARNER STILL VERY YOUNG!"
        Case 5
            ConvertBirthdayToGrade = "PP1"
        Case 6
            ConvertBirthdayToGrade = "PP2"
        Case 7
            ConvertBirthdayToGrade = "GRADE 1"
        Case 8
            ConvertBirthdayToGrade = "GRADE 2"
        Case 9
            ConvertBirthdayToGrade = "GRADE 3"
        Case 10
            ConvertBirthdayToGrade = "GRADE 4"
        Case 11
            ConvertBirthdayToGrade = "GRADE 5"
        Case 12
            ConvertBirthdayToGrade = IIf(Date < #5/1/2022#, "Class6", "Grade6")
        Case 13
            ConvertBirthdayToGrade = "CLASS 7"
        Case 14
            ConvertBirthdayToGrade = "CLASS 8"
        Case Is >= 15
            ConvertBirthdayToGrade = "LEARNER NO LONGER IN SCHOOL! CHECK BIRTH DATE!!"
        End Select
    
    
    End Function
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #22
    erickemboi is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    73
    Perfect. Thank you so much. God bless you. Once again, thank you.👏👏👏👏👏👏

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 34
    Last Post: 12-28-2017, 09:09 PM
  2. Replies: 2
    Last Post: 08-05-2015, 04:06 PM
  3. Replies: 4
    Last Post: 06-04-2014, 11:24 PM
  4. Replies: 3
    Last Post: 02-21-2014, 11:36 AM
  5. Replies: 2
    Last Post: 09-10-2009, 08:21 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums