Results 1 to 5 of 5
  1. #1
    nebula81 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Feb 2013
    Posts
    4

    How to combine the date

    Hi, I have a table that contains name, start date, end date. My problem is, i want to combine the date to one list by using query. Sample of data as following:

    Name Start_Date End_Date
    Sarah 23-Feb-13 25-Feb-13
    John 20-Feb-13 22-Feb-13
    MIke 20-Feb-13 21-Feb-13

    I want the result to be like this:

    Combine_Date
    20-Feb-13


    21-Feb-13
    22-Feb-13
    23-Feb-13
    24-Feb-13
    25-Feb-13


    Please help.

    Thank you

  2. #2
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Check out if Union Query is of any help.

    Thanks

  3. #3
    nebula81 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Feb 2013
    Posts
    4
    I have tried...but 24-Feb13 not in the list.

  4. #4
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Quote Originally Posted by nebula81 View Post
    I have tried...but 24-Feb13 not in the list.
    oops, sorry,
    missed out that 24th is not present in the 2 columns.
    Just hold on till some one comes along
    else
    Will try to revert asap.

    Thanks

  5. #5
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Currently do not know how to do this with a standalone query.
    Till some one comes along,
    If you are open to storing the generated dates in a New Table, then,
    save the below function & run it. The table name has been taken as myTable.

    Code:
    Public Function GenerateDatesForReport_1()
        
    Dim dbs As Databasetbl As TableDefRepDate As FieldstrTableName As Stringtdf As TableDef
        Set dbs 
    CurrentDb
        
        
    ' _________________________________________________________________________
        ' 
    Get the Start Date End Date to generate the table tblReportDates
        Dim sqlStartEndDate 
    As String
        Dim rst 
    As DAO.Recordset
        
        sqlStartEndDate 
    "SELECT Min([Start_Date]) AS StartDate1, Max([End_Date]) AS EndDate1 FROM myTable"
        
    Debug.Print sqlStartEndDate
        Set rst 
    dbs.OpenRecordset(sqlStartEndDate)
        
        
    Dim StartDate
        Dim EndDate
        
        StartDate 
    rst![StartDate1]
        
    Debug.Print StartDate
        EndDate 
    rst![EndDate1]
        
    Debug.Print EndDate
        
        
        
        
    ' _________________________________________________________________________
        ' 
    Start of Delete table tblReportDates if it exists
        strTableName 
    "tblReportDates"
        
    On Error Resume Next
        Set tdf 
    dbs.TableDefs(strTableName)

        If 
    Err 3265 Then
            
    ' Table does not exist.
            '   
    TableExists False
        
    Else
            
    ' Table exists.
            ' 
    TableExists True
            DoCmd
    .DeleteObject acTablestrTableName
        End 
    If
        
        
    ' Create the empty table for ReportDates
        Set tbl = dbs.CreateTableDef(strTableName)
        Set fld = tbl.CreateField("TheDate", dbDate)

        tbl.Fields.Append fld
        dbs.TableDefs.Append tbl
        dbs.TableDefs.Refresh
        ' 
    End of deleteing tblReportDates if it exists
        
    ' _________________________________________________________________________
        
        ' 
    Start of generating the Report Dates for the tblReportDates based on the Start End Dates provided
        Dim NewRepDate
        Dim NewEntryDate
        Dim strsqlInsert
        NewEntryDate 
    StartDate
        Debug
    .Print NewEntryDate
        
    For NewEntryDate To EndDate
            
    'Debug.Print i
            
            NewRepDate = NewEntryDate
            strsqlInsert = "INSERT INTO tblReportDates (TheDate) VALUES (#" & NewRepDate & "#)"
            Debug.Print strsqlInsert
            
            dbs.Execute (strsqlInsert)
            
            NewEntryDate = DateAdd("d", 1, NewRepDate)
        
        Next
        ' 
    End of generating the Report Dates for the tblReportDates
        
    ' _________________________________________________________________________
        '
    MsgBox ("Successful")

    End Function 
    Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 02-16-2013, 09:11 AM
  2. How to combine two columns into one
    By JRCharlie in forum Queries
    Replies: 4
    Last Post: 01-20-2013, 01:09 AM
  3. Code to combine report filter and date range
    By rhubarb in forum Reports
    Replies: 17
    Last Post: 10-28-2011, 03:08 PM
  4. Combine queries
    By thart21 in forum Queries
    Replies: 1
    Last Post: 03-05-2010, 01:39 PM
  5. Combine fields into one
    By cotri in forum Forms
    Replies: 2
    Last Post: 03-04-2010, 02:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums