Ok, I reviewed your sample database and as mentioned earlier, you are pretty much asking for a development project in a forum that was designed to answer specific questions about certain aspects of Access (i.e., Forms, Tables, Reports, VBA Code) or specific questions about Access functions, etc. Just being candid at this point to help you with future questions you may want to post here on EE. The experts here including myself are not doing development work here ... just answering questions a user may be having trouble with. Based on your last post, you have about 4 different request/questions nested in that one post. That's kind of was the basis for my original suggestion which was for you to make contact with and establish a relationship with a Access Developer the will develop those types of request for you so you can use those as a guide to study and get started with Advanced Access programming techniques if you are going to be handling those types of request. In all due fairness ... there are clients that have to pay a consulting fee to a developer in order to accomplish what you are asking here.
I don't generally do this which is take on a development project in this forum for reasons stated above but I fixed your report to do what you were asking so as to close out this question and move on. Here are the specifics ...
1.) Open the attached SOS_Fixed.mdb and then open the Form frmDailyReport. This is where you will run the report from.
2.) I notice where you are using some field names that are reserved in Access (NAME, DATE). You may want to avoid using those for field names in the future. That will cause some problems as Access will try to call a function if you don't wrap the field name in brackets.
3.) Basically, I'm using your query DailyReport to populate a Temp table named tblTempAssignments. Then loop through this table based on a Distinct Student Name with a recordset filtered by student, due date and not completed. I also store the selected assignment types down to a temp table tblTempAssignType that's used for criteria in the qryDailyReportTempTbl which appends the selected records into the temp table. The function RescheduleAssignments is stored in Module1 under the Modules Objects and is also displayed below. Please review then run the report and ask any questions if you have any.
ET
Function RescheduleAssignments()
On Error GoTo Err_Handler
DoCmd.SetWarnings False
'Declare Variables
Dim varTotalAssignments 'Holds the count of total assignments in the temp table
Dim varGroupDetails 'Holds the number of assignments for the relative date group
Dim varGroupDetails1 'Holds the number of remaining assignments after an even distribution has been calculated.
Dim varReschedule_StartDate 'Holds the re-schedule start date entered on the form
Dim varCounter 'Counter variable
Dim rst As dao.Recordset 'Recordset on the temp table
Dim rst1 As dao.Recordset 'Recordet of unique student id selected for the report
Dim varRescheduleDays 'Hold the number of re-schedule days entered on the form.
Dim varArray() 'Creates an array to hold the schedule days.
Dim X As Integer 'Integer counter
Dim rstAssignType As dao.Recordset 'Holds the selected assignment types
'Run the delete query here to clear the temp tables
DoCmd.RunSQL "DELETE * FROM tblTempAssignments;"
DoCmd.RunSQL "DELETE * FROM tblTempAssignType;"
'Write/store each selected assignment type to the temp table for use in the query
Set rstAssignType = CurrentDb.OpenRecordset("tblTempAssignType", dbOpenDynaset)
Dim varItem
For Each varItem In Forms!frmDailyReport.List7.ItemsSelected
rstAssignType.AddNew
rstAssignType!assignment_type = Forms!frmDailyReport.List7.Column(0, varItem)
rstAssignType.Update
Next varItem
'Run the append query here to populate the temp table with the selected assignments for the report
DoCmd.OpenQuery "qryDailyReportTempTbl", acViewNormal
'Set variable value
varRescheduleDays = Forms!frmDailyReport!TxtDays 'Holds the number of re-schedule days entered on the form.
'Inatialize the array based on the days entered on the form
ReDim Preserve varArray(varRescheduleDays)
'Open the temp table, loop through each distinct student name and fill in the re-scheduled date field based on the
'the number of assignments for the relative student.
'The code will bump the start date by 1 day bypassing Saturday and Sunday.
Set rst1 = CurrentDb.OpenRecordset("SELECT DISTINCT [name] FROM tblTempAssignments ORDER BY [name];", dbOpenDynaset)
If rst1.RecordCount > 0 Then
rst1.MoveFirst
Do Until rst1.EOF 'This will loop through each distinct student name.
'This will create a second recordset of just the current student name in rst1.
Set rst = CurrentDb.OpenRecordset("SELECT * FROM tblTempAssignments WHERE [name] ='" & rst1![Name] & "' AND [date] <=#" & Date & "# AND completed_ind = 0 ORDER BY [date];", dbOpenDynaset)
If rst.RecordCount > 0 Then
rst.MoveLast
rst.MoveFirst
varReschedule_StartDate = Forms!frmDailyReport!TxtStartDate 'Holds the start date entered on the form. Bypass Saturday and Sunday
If DatePart("W", varReschedule_StartDate) = 7 Then
varReschedule_StartDate = varReschedule_StartDate + 2
End If
If DatePart("W", varReschedule_StartDate) = 1 Then
varReschedule_StartDate = varReschedule_StartDate + 1
End If
varTotalAssignments = rst.RecordCount 'Count of the total assignments in the temp table for the current student that are past due
varGroupDetails = Int((varTotalAssignments / varRescheduleDays)) 'Holds the even distribution of assignments based on the number of re-schedule days
varGroupDetails1 = varTotalAssignments - (varGroupDetails * varRescheduleDays) 'Holds the remaining details after even distribution over re-scheule days
'Evenly distribute assignments over re-schedule days in the array
For X = 1 To UBound(varArray())
varArray(X) = varGroupDetails
Next X
'Distribute the remaining assignments in the array until all depleted
varCounter = 1
Do Until varGroupDetails1 = 0
varArray(varCounter) = varArray(varCounter) + 1
varGroupDetails1 = varGroupDetails1 - 1
varCounter = varCounter + 1
Loop
For X = 1 To UBound(varArray()) 'Write the re-schedule date to the temp table the number of times stored in each array element for the student.
varCounter = varArray(X)
Do Until varCounter = 0
rst.Edit
rst!RESCHEDULED_DATE = varReschedule_StartDate
rst.Update
varCounter = varCounter - 1
rst.MoveNext
Loop
'Bump the start date and bypass Saturday & Sunday
varReschedule_StartDate = varReschedule_StartDate + 1
If DatePart("w", varReschedule_StartDate) = 7 Then
varReschedule_StartDate = varReschedule_StartDate + 2
End If
If DatePart("W", varReschedule_StartDate) = 1 Then
varReschedule_StartDate = varReschedule_StartDate + 1
End If
Next X
End If
rst1.MoveNext
Loop
End If
'Close the recordsets
If Not rst Is Nothing Then 'Recordset is open
rst.Close
Set rst = Nothing
End If
If Not rst1 Is Nothing Then 'Recordset is open
rst1.Close
Set rst1 = Nothing
End If
If Not rstAssignType Is Nothing Then 'Recordset is open
rstAssignType.Close
Set rstAssignType = Nothing
End If
'Open the report
DoCmd.OpenReport "DailyReport", acViewPreview
Exit_Err_Handler:
Exit Function
Err_Handler:
MsgBox Err.Number & " " & Err.DESCRIPTION
Resume Exit_Err_Handler
End Function