Months automatic breakdown breakdown (1 Viewer)

Capitala

Member
Local time
Today, 20:44
Joined
Oct 21, 2021
Messages
58
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
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:44
Joined
Oct 29, 2018
Messages
21,473
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?
 

Capitala

Member
Local time
Today, 20:44
Joined
Oct 21, 2021
Messages
58
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
 

Capitala

Member
Local time
Today, 20:44
Joined
Oct 21, 2021
Messages
58
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.
 

moke123

AWF VIP
Local time
Today, 15:44
Joined
Jan 11, 2013
Messages
3,920
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.
 

Capitala

Member
Local time
Today, 20:44
Joined
Oct 21, 2021
Messages
58
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.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:44
Joined
May 7, 2009
Messages
19,242
period 1: from 5-12-2020 to 4-1-2021, period 2: from 5-1-2021 to 4-2-2021
using query alone + additional table, you can accomplished the same.
see query1.
 

Attachments

  • contract.accdb
    496 KB · Views: 224

Users who are viewing this thread

Top Bottom