Months automatic breakdown breakdown

Capitala

Member
Local time
Today, 15:59
Joined
Oct 21, 2021
Messages
91
Good day!
I'm working on tenancy contract project. I enter the start date and end date manually. I need a code to break down tenancy contract to periods automatically.
i.e. if the contract starts on 6-12-2020 and ends on 15-5-2020, it should break them down as follows:
period 1: from 5-12-2020 to 4-1-2021, period 2: from 5-1-2021 to 4-2-2021

I a need a code to do that.
Thanks in advance
 
Hi. Welcome to AWF!

Did you want the code to return just one period or all of them? If all of them, do you have a table for storing them?
 
Hi. Welcome to AWF!

Did you want the code to return just one period or all of them? If all of them, do you have a table for storing them?
Thanks for your kind support. I have a table already for that
 
Can you show us the table structure?
It should be like that, where the start date and end date will be taken from external fields
Contract_idPeriodFromTo
115-1-20204-2-2020
125-2-20204-3-2020
13Etc.Etc.
 
you could do something along these lines:

Code:
Sub OneYear(dteStart As Date)

    Dim i As Integer
    Dim dteS As Date
    dteS = dteStart

    For i = 1 To 12
        Debug.Print i, dteS, DateAdd("m", 1, dteS) - 1
        dteS = DateAdd("m", 1, dteS)

    Next i

End Sub

Code:
 1            1/5/2021      2/4/2021
2            2/5/2021      3/4/2021
3            3/5/2021      4/4/2021
4            4/5/2021      5/4/2021
5            5/5/2021      6/4/2021
6            6/5/2021      7/4/2021
7            7/5/2021      8/4/2021
8            8/5/2021      9/4/2021
9            9/5/2021      10/4/2021
10           10/5/2021     11/4/2021
11           11/5/2021     12/4/2021
12           12/5/2021     1/4/2022

Note: From and To are reserved words and should not be used as field names.
 
you could do something along these lines:

Code:
Sub OneYear(dteStart As Date)

    Dim i As Integer
    Dim dteS As Date
    dteS = dteStart

    For i = 1 To 12
        Debug.Print i, dteS, DateAdd("m", 1, dteS) - 1
        dteS = DateAdd("m", 1, dteS)

    Next i

End Sub

Code:
 1            1/5/2021      2/4/2021
2            2/5/2021      3/4/2021
3            3/5/2021      4/4/2021
4            4/5/2021      5/4/2021
5            5/5/2021      6/4/2021
6            6/5/2021      7/4/2021
7            7/5/2021      8/4/2021
8            8/5/2021      9/4/2021
9            9/5/2021      10/4/2021
10           10/5/2021     11/4/2021
11           11/5/2021     12/4/2021
12           12/5/2021     1/4/2022
Thanks a mile. I'll try it.
 

Users who are viewing this thread

Back
Top Bottom