Results 1 to 5 of 5
  1. #1
    stuart_roberts is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Oct 2016
    Posts
    14

    Create entries between dates

    Hi all

    So I’ve had a look and can’t find an answer to my problem, I’ll do my best to explain it.



    So I have a form with two fields, start date and end date, so what I want to do is create entries between these two dates, so for example the start and end date are a week apart, it’ll create 7 entries one for each day, this is so I can view them in a calendar layout or gannt chart.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    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
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    271
    You need a loop that goes through your dates and inserts one record per day, see attached
    multipleinsert.accdb

    Code:
    Private Sub Comando1_Click()
        Dim startDate As Date
        Dim endDate As Date
        
        startDate = Me.txtDate1
        endDate = Me.txtDate2
        
        Dim db As DAO.Database
        Set db = CurrentDb
        
        For i = startDate To endDate
           Dim rs As DAO.Recordset
           Set rs = db.OpenRecordset("tblDates", dbOpenDynaset)
           rs.AddNew
           rs!theDate = i
           rs.Update
        Next i
    End Sub

  4. #4
    stuart_roberts is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Oct 2016
    Posts
    14
    thank you worked a treat, do you think this would also work with time and date, so start date would be be 17:00 27/01/2023 to 12:00 30/01/2023

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Why don't you try then come back with outcome.
    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.

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

Similar Threads

  1. Replies: 5
    Last Post: 05-25-2022, 10:01 AM
  2. Using Queries to create entries
    By JuanL in forum Queries
    Replies: 5
    Last Post: 04-05-2022, 09:17 AM
  3. Replies: 1
    Last Post: 07-10-2015, 01:58 PM
  4. Replies: 1
    Last Post: 05-20-2013, 01:45 PM
  5. Replies: 4
    Last Post: 04-23-2012, 05:07 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