Solved

Break down a date range into the months in ACCESS 2010

Posted on 2013-12-17
2
564 Views
Last Modified: 2013-12-17
I have process that uses date ranges in a row  for each project, say Start Date of 2/15/2013 and End Date of 6/18/2013.  What I need to do is take this date range and separate it into its various months, that is, the destination table would have a column for each month.  The Data would be transformed from one column in the source to multiple column in the destination, that is, the destination columns and data should be like:

Source Row:  
ProjectID    UserID     StartDate     EndDate
Prj_1             someone  2/15/2013   6/18/2013

Would be transformed into the below table configuration:


ProjectI   USerID      StartDate         EndDate
PRJ_1       someone    2/15/2013      2/28/2013
PRJ_1       someone    3/1/2013         3/31/2013
PrJ_1       someone     4/1/2013         4/30/213
Prj_1       someone      5/1/2013        5/31/2013
Prj_1       someone      6/2/2013       6/18/2013

Just not sure how to go about this

Sandra
0
Comment
Question by:ssmith94015
2 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39725813
you will need VBA codes to do this, and populate a new table "tblProjects_details" from records in your original table "tblProjects" (in this code)

Sub breakDates()
Dim rs As DAO.Recordset, rs1 As DAO.Recordset
Dim sDate As Date, eDate As Date

Set rs = CurrentDb.OpenRecordset("tblProjects")
Set rs1 = CurrentDb.OpenRecordset("tblProjects_details")
rs.MoveFirst

Do Until rs.EOF
    sDate = rs!StartDate
    Do
   
    eDate = DateSerial(Year(sDate), Month(sDate) + 1, 0)
    If eDate >= rs!enddate Then eDate = rs!enddate
        With rs1
            .AddNew
            !ProjectID = rs!ProjectID
            !UserID = rs!UserID
            !StartDate = sDate
            !enddate = eDate
            .Update
        End With
        sDate = DateSerial(Year(sDate), Month(sDate) + 1, 1)
    Loop Until eDate >= rs!enddate
rs.MoveNext
Loop
rs.Close
rs1.Close
End Sub
0
 

Author Closing Comment

by:ssmith94015
ID: 39725821
Yes, that did it.  I knew there was a loop in there someplace.

thank you, Sandra
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question