Solved

Break down a date range into the months in ACCESS 2010

Posted on 2013-12-17
2
573 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
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…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

726 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