how to make calender for 365 days

arul mozhi
arul mozhi used Ask the Experts™
I am a beginner in MS Access and using MS Access 2000. I have slowly and consistently learning the correct ways from the people like you. Now, for one of my database on Workers/Staffs Attendance, I need to fill one of a field with date from 1 Jan XXXX (now 2017) to 31 Dec XXXX.
3-jan-2017 on..

I need help to create query to automatically fill that filed with continuous date and next field with weekdays (sunday, monday..etc).
Please help me with sample coding and if any other easy steps are there, then let me know.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012


  Usually pre-filling a table with records is a bad idea.   If your tracking attendance, you would simply record what days they attended.  Then when reporting, figure out if they had a day for that record or not.

Top Expert 2016
see this sample db, it fills the table tblDates by running the sub populateTableDate
Distinguished Expert 2017

I agree with Jim.  It doesn't make any sense to prefill a table with empty attendance records.  it is especially bad when you know that at least 25% of them will NEVER be used.  Why put in a record for every day of the month when people only work 5 days a week.

The example Rey posted was simplistic and it just adds one record per day for a whole year.  What you are asking to do I believe would be to generate a month's worth of records for EACH worker.  That is still poor practice.  However, if you have a schedule table so you can identify which week days a person generally works, there is some logic (but not much) to pre-generating those records.  So if Sallie works mon-fri, you could generate an empty attendance record for those five days for all occurrences in a month.  Or Sam works weekends and holidays so the code would generate Sat and Sun records for Sam for a month but there would also need to be a holiday table available to include holidays and by extension, exclude them from the standard record generation.

In general, it is far better to add the records as needed.  That way you don't clutter up the database with records that are never relevant.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Most Valuable Expert 2015
Distinguished Expert 2018
You can automatically add records when the form loads to always have records, say, a week ahead:

Private Sub Form_Load()

    Const DaysToAdd As Integer = 7  ' Adjust as needed.
    Dim rs          As DAO.Recordset
    Dim NextDate    As Date
    Set rs = Me.RecordsetClone
    rs.Sort = "NameOfYourDateField"
    Set rs = rs.OpenRecordset()
    NextDate = rs!NameOfYourDateField.Value
    While NextDate < DateAdd("d", DaysToAdd, Date)
        NextDate = DateAdd("d", 1, NextDate)
            rs!NameOfYourDateField.Value = NextDate
            ' Assign values to mandatory fields if any (not AutoNumber):
            ' rs!SomeField.Value = SomeValue
            ' rs!SomeOtherField.Value = SomeOtherValue       
    Set rs = Nothing
End Sub

Open in new window

Most Valuable Expert 2015
Distinguished Expert 2018

Question was fully answered.
Distinguished Expert 2017

Swell.  Every time Suzie, Sam, and the other 50 staff members login, they'll all add the same useless records; probably multiple times each day if this is a form they go to multiple times.  Hope this user knows enough to add a primary key or unique index to the table or it's going to grow like wildfire.  But the question was "fully" answered.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial