Results 1 to 3 of 3
  1. #1
    maxbre is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    38

    fill a table with a sequence of hourly dates

    hi all

    I need to fill a table with a sequence of hourly dates;
    this is my attempt so far....


    Code:
    Private Sub fill_tbl_dates()
    
    
    'del old recs in the table
    sql_del_recs = "DELETE * FROM data_ok"
    DoCmd.RunSQL sql_del_recs
    
    
    'def start and end date
    start_date = #1/1/2014#
    end_date = #10/1/2014#
    
    
    'insert first rec in the table
    sql_insert_date = "INSERT INTO data_ok (data) VALUES ('" & start_date & "');"
    DoCmd.RunSQL sql_insert_date
    
    
    ' def start date for cycling
    date_add = DateAdd("h", 1, start_date)
    
    
    'def n cycles
    n_hour = DateDiff("h", date_add, end_date)
    
    'here the cycle for I'm stuck at....
    
    For i = 1 To n_hour
    
    
    Next
    
    
    End Sub

    ....definitely stuck at the proper way of conceiving the loop (or an alternative solution) to fill the table with dates



    any hints for that?

    thank you


    max

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Try:

    'del old recs in the table
    CurrentDb.Execute "DELETE * FROM data_ok"

    'def start and end date
    start_date = #1/1/2014#
    end_date = #10/1/2014#

    'def n cycles
    n_hour = DateDiff("h", DateAdd("h", 1, start_date), end_date)

    For i = 1 To n_hour
    CurrentDb.Execute "INSERT INTO data_ok (data) VALUES ('" & DateAdd("h", i, start_date) & "');"
    Next
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    maxbre is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    38
    yes, thank you, it's perfectly working!

    ...and this is my final code snipped for any future reference

    thank you again for the support

    Code:
    'del old recs in the table
    CurrentDb.Execute "DELETE * FROM data_ok"
    
    'def start and end date
    '#m/d/y
    start_date = #3/27/2014 1:00:00 PM#
    end_date = #4/10/2014 3:00:00 PM#
    
    
    'def n cycles
    
    'upper end open
    n_hour = DateDiff("h", DateAdd("h", 1, start_date), end_date)
    
    'upper end close
    'n_hour = DateDiff("h", start_date, end_date)
    
    
    For i = 0 To n_hour
    CurrentDb.Execute "INSERT INTO data_ok (data) VALUES ('" & DateAdd("h", i, start_date) & "');"
    Next

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

Similar Threads

  1. Insert sequence of numbers in table
    By amrut in forum Queries
    Replies: 2
    Last Post: 05-09-2013, 07:00 AM
  2. Add sequence number to time punch table
    By aflamin24 in forum Queries
    Replies: 1
    Last Post: 07-20-2012, 05:43 PM
  3. Replies: 1
    Last Post: 05-07-2012, 08:21 AM
  4. Count how many records hourly?
    By shootnow in forum Queries
    Replies: 1
    Last Post: 08-02-2011, 06:59 PM
  5. Replies: 5
    Last Post: 04-28-2011, 05:10 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