
Originally Posted by
ggs
Thanks both for your help. June7 Tried to thank you but MsgBox "You have to spread some thanks around before you can thank June7 again"
Hope that doesn't mean you have to stop helping me
- The DB - yes, I had prepopulated [Date2Day] after trying allsorts (not licorice) I Excel ed Jan1 thru Dec31 and imported. Cheating I know
Only thing I now need to make up some templates 2013, 2014 etc (thats hopeful)
Anyway the code worked like magic and is just what I wanted
Instead of using Excel, here is some code to help you along. I didn't add any comments...
Your task is to understand how this works. There WILL be a test....
Copy the code and put it into a module. Change "YourTable" to the name of your table. Then press execute (F5) to run or (F8) to single step the code.
Code:
Public Sub AddDates()
Const BegDate As Date = #1/1/2013#
Dim i As Integer
Dim sSQL As String
Dim TheDate As Date
For i = 0 To 364
TheDate = DateAdd("d", i, BegDate)
sSQL = "INSERT INTO YourTable (Date2Day) VALUES (#" & TheDate & "#);"
CurrentDb.Execute sSQL, dbFailOnError
Next
MsgBox "Done"
End Sub
**This is quick and dirty. Does not take into account Leap years.** You might be missing the last day of the year.
Do you have the Indexed property for the field field "Date2Date" set to "Yes (No Duplicates)"? This will ensure you cannot have two dates that are the same.