I am using the following code to automatically schedule employees. What I need to alter here is I need the ability to be able to set the number of "employees to be scheduled for each shift". In the below code you will see you can only set it for "shift 2". I have tried to alter the code but I cannot seem to get it correct. Any help would be greatly appreciated
Code:
Private Sub Command23_Click()
Dim vEmployee As Long
Dim vDate As Date
Dim vShift As Long
vDateCount = 1
vEmployee = Me.txtEmployee
vDate = Me.txtStartDate
DoCmd.SetWarnings False
Do While vDateCount <= 5
vShift = 1
' store this number and the start date and the shift number in detail record new record
DoCmd.RunSQL "INSERT INTO tblShiftDetail " & "(EmployeeNumber, ShiftNumber, ShiftDetailDate ) VALUES " & "('" & vEmployee & "', '" & vShift & "', '" & vDate & "');"
' get another employee
vEmployee = vEmployee + 1
If vEmployee > 9 Then ' change the 9 to however many employees you have
vEmployee = 1
End If
' store 2nd employee and start date and shift # in detail new record
DoCmd.RunSQL "INSERT INTO tblShiftDetail " & "(EmployeeNumber,ShiftNumber,ShiftDetailDate ) VALUES " & "('" & vEmployee & "', '" & vShift & "', '" & vDate & "');"
vShift = 2
vCount = 1
Do While vCount <= 2 ' need 2 employees for this shift
vEmployee = vEmployee + 1
If vEmployee > 9 Then ' change the 9 to however many employees you have
vEmployee = 1
End If
' store employee and shift and date in detail new record
DoCmd.RunSQL "INSERT INTO tblShiftDetail " & "(EmployeeNumber,ShiftNumber,ShiftDetailDate ) VALUES " & "('" & vEmployee & "', '" & vShift & "', '" & vDate & "');"
vCount = vCount + 1
Loop
vShift = 3
vEmployee = vEmployee + 1
If vEmployee > 9 Then ' change the 9 to however many employees you have
vEmployee = 1
End If
' store employee and shift and date in detail new record
DoCmd.RunSQL "INSERT INTO tblShiftDetail " & "(EmployeeNumber,ShiftNumber,ShiftDetailDate ) VALUES " & "('" & vEmployee & "', '" & vShift & "', '" & vDate & "');"
vEmployee = vEmployee + 1
If vEmployee > 9 Then ' change the 9 to however many employees you have
vEmployee = 1
End If
vDate = vDate + 1
vDateCount = vDateCount + 1
Loop
DoCmd.SetWarnings True
End Sub