Solved

Break down a date range into the months in ACCESS 2010

Posted on 2013-12-17
2
545 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 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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
Comment Utility
Yes, that did it.  I knew there was a loop in there someplace.

thank you, Sandra
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
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 …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now