?
Solved

Break down a date range into the months in ACCESS 2010

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
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…
Suggested Courses

765 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