Auto Create Table

fenhow

Registered User.
Local time
Today, 14:12
Joined
Jul 21, 2004
Messages
599
Hello, I am looking for a way to auto create a table with a macro or code.
What I have is a Start Date and a Term in months.
If I have a start date of 1/1/2016 and it is for 12 months. I want to create a table that has a date column with 1/1/2016, next record 2/1/2016 and so on for the total of 12 months.
Is this possible?
Many thanks.
Fen
 
I probably wouldn't create a table, I'd populate one using a For/Next loop, the AddNew method of a recordset and the DateAdd() function.
 
Yes, that is what I meant. I already have the table. Any chance for an example I can look at?
Fen
 
I found this and it works however it adds one day versus one month..

Public Sub FillDates()
Dim Db As DAO.Database
Dim rs As Recordset
Dim dteFrom As Date
Set Db = CurrentDb
Set rs = Db.OpenRecordset("tblDates")
dteFrom = #1/1/2016#
dteTo = #1/1/2017#
With rs
Do Until dteFrom = dteTo + 1 ' (the +1 will include 1/1/2018)
.AddNew
!PaymentDate = dteFrom
.Update
dteFrom = dteFrom + 1
End With
Set Db = Nothing
Set rs = Nothing
End Sub
 
I mentioned the DateAdd() function, which you'd use in place of the +1:

dteFrom = dteFrom + 1
 

Users who are viewing this thread

Back
Top Bottom