autodate like autonum in access2003

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way of automatically populating the date field of a basic diary
database I created, so that I can pre-create 365 records with a years worth
of dates?
 
Public Sub CreateDates(ByVal StartDate As Date)

Dim dtmDate As Date

For dtmDate = StartDate To DateAdd("yyyy", 1, StartDate) - 1
CurrentDb.Execute "INSERT INTO tblTest (TestDate) VALUES (#" & _
Format$(dtmDate, "mm/dd/yyyy") & "#)", dbFailOnError
Next dtmDate

End Sub

Where 'tblTest' is the name of your table, and 'TestDate' is the name of
your date/time field.

Example of use, in Immediate Window ...

createdates(date())
 
Is there a way of automatically populating the date field of a basic diary
database I created, so that I can pre-create 365 records with a years worth
of dates?

You'll need either VBA, or an auxiliary table - or, you can use Excel
to create the data. Open a spreadsheet; enter the start date and the
day after; and use Fill Down to fill out the year. Copy and paste into
an Access table.

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top