Add a range of dates to a table (1 Viewer)

gemadan96

Registered User.
Local time
Today, 08:34
Joined
Oct 12, 2012
Messages
26
I want to create a form that ask the user for a start date and an end date. Then when the click OK it will append a record to a table for each date and each date in between based on the increment. For example the start date is 6/20/2014 and the end date is 6/27/2014 and the increment will be 1 day. I want to add records to my table for:

6/20/2014
6/21/2014
6/22/2014
6/23/2014
6/24/2014
6/25/2014
6/26/2014
6/27/2014

I have the form setup to to prompt for the start and end dates. It's the VBA coding to do the dateadd function in a loop I'm trying to figure out.
 

plog

Banishment Pending
Local time
Today, 07:34
Joined
May 11, 2011
Messages
11,669
It's the VBA coding to do the dateadd function in a loop I'm trying to figure out.

When you don't post specific questions or code, we interpret 'trying to figure out' as 'trying to get someone to do for me'.

What do you have so far and where are you getting stuck?
 

gemadan96

Registered User.
Local time
Today, 08:34
Joined
Oct 12, 2012
Messages
26
What I was looking for was a suggestion on how to start it, not necessarily for someone to do it. After all this is a forum where people are usually helpful.

In any case I was able to figure it out.

Here is the code that works and even inserts the weekday name. Somebody else might find it useful, especially a non programmer.

Private Sub AddDates_Click()
Dim dbs As Database
Dim strDayName As String
Dim sDate As Date
Dim eDate As Date
sDate = StartDate
eDate = EndDate

Set dbs = CurrentDb
NextDate = sDate

For i = NextDate To eDate
strDayName = WeekdayName(Weekday(NextDate))
strsqlInsert = "Insert into ClassDaysTemp (TempDate, DayName) VALUES (#" & NextDate & "#, '" & strDayName & "')"
dbs.Execute (strsqlInsert)
NextDate = DateAdd("d", 1, NextDate)
Next

End Sub
 

GinaWhipp

AWF VIP
Local time
Today, 08:34
Joined
Jun 21, 2011
Messages
5,899
Thanks for sharing your solution, I'm certain it's bound to help someone else! :D
 

Users who are viewing this thread

Top Bottom