Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Break down a date range into the months in ACCESS 2010

Posted on 2013-12-17
2
Medium Priority
?
600 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 2000 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

650 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