Sub DailyDate() 'This section sets up all the variables used in the procedure Dim dbs As DAO.Database Dim rst As DAO.Recordset Dim frm As Form Dim intCount As Integer Dim dteStart As Date Dim dteEnd As Date Dim dteStartDate As Date Dim dteEndDate As Date Dim dteYearDate Dim txtBranchID As Recordset Dim liRecordIndex As Integer On Error GoTo Error_Handler Set dbs = CurrentDb Set rst = dbs.OpenRecordset("DailyDate") Set frm = Forms("frmCreateDay") 'This section gets the values from the textboxes on the form 'and sets intCount to 1 (intCount tracks the week number) dteStartDate = frm.Controls("txtStart") dteEndDate = frm.Controls("txtEnd") dteYearDate = frm.Controls("txtYear") intCount = 1 'This section sets the start and end dates for the first week dteStart = dteStartDate dteEnd = dteStart + 1 'This loops through until the end date is reached 'If your end date doesn't fall properly at the end of a week it will 'cut off at the last week end date BEFORE the total date is reached 'Each time it loops through it adds one record to the table Do Until dteEnd > dteEndDate With rst .AddNew !WeekNo = intCount !Date = dteStart !YearDate = (dteYearDate) .Update End With 'Increments the start and end dates and the week number intCount = intCount + 1 dteStart = dteStart + 1 dteEnd = dteStart Loop Set frm = Nothing Set rst = Nothing Set dbs = Nothing intCount = MsgBox("Weeks created.", vbOKOnly) Exit_Sub: Exit Sub Error_Handler: If Err.Number = 3022 Then MsgBox "Weeks already exist!", vbOKOnly + vbCritical, "Error!" Else MsgBox Err.Number & vbCrLf & Err.Description, vbOKOnly + vbCritical, "Error!" End If Exit Sub End Sub