Dim WSheet As Worksheet
Dim XCount, YCount, SheetIndex As Long
Dim CellCount, Count, ComboCount, RowNumber, Column As Integer
Dim Employees, Employee, SelectedEmployee As Range
Dim SheetName, EmployeeName, DisplayName, Surname, Titles, PAYENumber, Temp, TemporaryWeek, LocationNumber, Location As String
Dim Found, Valid, ResumptionValid, ExistingSickness As Boolean
Dim WeekEnding As Date
Dim a, b
Private Sub UserForm_Initialize()
cboEmployee.Clear
With Sheets("Staff")
Set Employees = .Range(.Range("B2"), .Range("B" & Rows.Count).End(xlUp))
End With
ReDim ray(1 To Employees.Count)
For Each Employee In Employees
Surname = Right(Employee, Len(Employee) - InStrRev(Employee, " "))
Titles = Left(Employee, Len(Employee) - Len(Surname))
Count = Count + 1
ray(Count) = (Surname & ", " & Titles & " (" & Employee.Offset(, -1) & ")")
Next Employee
For XCount = 1 To UBound(ray) - 1
For YCount = XCount To UBound(ray)
If ray(YCount) < ray(XCount) Then
Temp = ray(XCount)
ray(XCount) = ray(YCount)
ray(YCount) = Temp
End If
Next YCount
Next XCount
With cboEmployee
.List = Application.Transpose(ray)
.ListIndex = 0
.SelStart = 0
.SelLength = Len(cboEmployee.Value)
End With
If Sheets("Sickness").Range("F2") > "" Then
With Sheets("Sickness").Range("F2:F1048576")
a = .Value
End With
With CreateObject("scripting.dictionary")
.comparemode = 1
For Each b In a
If Not .exists(b) Then .Add b, Nothing
Next
If .Count Then
cboReportingSupervisor.List = Application.Transpose(.keys)
cboReportingSupervisor2.List = Application.Transpose(.keys)
End If
End With
End If
If Environ("Username") Like "*.*" Then
cboReportingSupervisor.Value = StrConv(Left(Environ("Username"), InStr(Environ("Username"), ".") - 1), vbProperCase) & " " & StrConv(Right(Environ("Username"), (Len(Environ("Username")) - InStr(Environ("Username"), "."))), vbProperCase)
cboReportingSupervisor2.Value = StrConv(Left(Environ("Username"), InStr(Environ("Username"), ".") - 1), vbProperCase) & " " & StrConv(Right(Environ("Username"), (Len(Environ("Username")) - InStr(Environ("Username"), "."))), vbProperCase)
End If
With cboReportingSupervisor
.SelStart = 0
.SelLength = Len(cboEmployee.Value)
End With
txtTime = Format(Now, "hh:mm")
txtShiftDate = Format(DateValue(Now) + 1, "d mmm yy")
txtTime2 = Format(Now, "hh:mm")
cboEmployee.SetFocus
End Sub
Private Sub cboEmployee_Change()
If Not cboEmployee.Value Like "* (#####)" Then
frmEmployeeNotFound.Show
If frmEmployeeNotFound.Tag = "Cancelled" Then
Unload frmEmployeeNotFound
With cboEmployee
.ListIndex = 0
.SelStart = 0
.SelLength = Len(cboEmployee.Value)
End With
Exit Sub
End If
End If
PAYENumber = Left(Right(cboEmployee.Value, 6), 5)
With Sheets("Staff")
Set Employees = .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
Set SelectedEmployee = Employees.Find(PAYENumber, LookIn:=xlValues)
End With
LocationNumber = Sheets("Staff").Cells(SelectedEmployee.Row, 3)
Location = Sheets("Staff").Cells(SelectedEmployee.Row, 4)
Me.lblLocation.Caption = Location & " (" & LocationNumber & ")"
cboLocation = Location
lblEmployee.Caption = cboEmployee.Value
lblLocation2.Caption = Location & " (" & LocationNumber & ")"
cboResumptionLocation = Location
End Sub
Private Sub txtShiftTime_AfterUpdate()
If IsDate(txtShiftTime.Value) And txtShiftTime.Value Like "*:*" Then
txtShiftTime.Value = Format(txtShiftTime.Value, "hh:mm")
Else
MsgBox ("Please enter a time in the format 'hh:mm'")
txtShiftTime = Format(TimeValue(Now), "hh:mm")
End If
End Sub
Private Sub txtshiftDate_AfterUpdate()
If IsDate(txtShiftDate.Value) And Not txtShiftDate.Value Like "*:*" Then
txtShiftDate.Value = Format(txtShiftDate.Value, "d mmm yy")
Else
MsgBox ("Please enter a date in the format 'dd/mm/yy'")
txttxtshiftDate = Format(DateValue(Now) - 1, "d mmm yy")
End If
End Sub
Private Sub txtTime_AfterUpdate()
If IsDate(txtTime.Value) And txtTime.Value Like "*:*" Then
txtTime.Value = Format(txtTime.Value, "hh:mm")
Else
MsgBox ("Please enter a time in the format 'hh:mm'")
txtTime = Format(TimeValue(Now), "hh:mm")
End If
End Sub
Private Sub chkUFN_Click()
If chkUFN.Value = True Then
lblExpectedDuration.visible = False
txtExpectedDuration.Enabled = False
txtExpectedDuration.visible = False
MultiPage1.Pages("pgeresumesickness").Enabled = True
Else
lblExpectedDuration.visible = True
txtExpectedDuration.Enabled = True
txtExpectedDuration.visible = True
MultiPage1.Pages("pgeresumesickness").Enabled = False
End If
End Sub
Private Sub txtResumptionDate_AfterUpdate()
If IsDate(txtResumptionDate.Value) And Not txtResumptionDate.Value Like "*:*" Then
txtResumptionDate.Value = Format(txtResumptionDate.Value, "d mmm yy")
Else
MsgBox ("Please enter a date in the format 'dd/mm/yy'")
txtResumptionDate = Format(DateValue(Now) + 1, "d mmm yy")
End If
End Sub
Private Sub txtResumptionShift_AfterUpdate()
If IsDate(txtResumptionShift.Value) And txtResumptionShift.Value Like "*:*" Then
txtResumptionShift.Value = Format(txtResumptionShift.Value, "hh:mm")
Else
MsgBox ("Please enter a time in the format 'hh:mm'")
txtResumptionShift = Format(TimeValue(Now), "hh:mm")
End If
End Sub
Private Sub txtTime2_AfterUpdate()
If IsDate(txtTime2.Value) And txtTime2.Value Like "*:*" Then
txtTime2.Value = Format(txtTime2.Value, "hh:mm")
Else
MsgBox ("Please enter a time in the format 'hh:mm'")
txtTime2 = Format(TimeValue(Now), "hh:mm")
End If
End Sub
Sub Validation()
Valid = False
If cboEmployee.Value = "" Then
MsgBox ("Please select an employee.")
cboEmployee.SetFocus
Exit Sub
End If
If txtShiftTime = "" Then
MsgBox ("Please enter the start time of their next rostered shift in the format 'hh:mm'.")
txtShiftTime.SetFocus
Exit Sub
End If
If txtShiftDate = "" Then
MsgBox ("Please enter the date of their next rostered shift in the format 'dd/mm/yy'.")
txtShiftDate.SetFocus
Exit Sub
End If
If cboLocation.Value = "" Then
MsgBox ("Please select the location of their next rostered shift.")
cboLocation.SetFocus
Exit Sub
End If
If txtReason = "" Then
MsgBox ("Please enter a reason for absence.")
txtReason.SetFocus
Exit Sub
End If
If cboReportingSupervisor.Value = "" Then
MsgBox ("Please enter the name of the supervisor reporting the sickness.")
cboReportingSupervisor.SetFocus
Exit Sub
End If
If txtCoverArranged = "" Then
MsgBox ("Please give any details of cover arranged, or who has arranged cover.")
txtCoverArranged.SetFocus
Exit Sub
End If
Valid = True
End Sub
Sub ResumptionValidation()
ResumptionValid = False
If txtResumptionShift = "" Then
MsgBox ("Please enter the start time of the shift for which they will be resuming in the format 'hh:mm'.")
txtResumptionShift.SetFocus
Exit Sub
End If
If cboResumptionLocation = "" Then
MsgBox ("Please enter the location at which they will be resuming.")
txtResumptionlocation.SetFocus
Exit Sub
End If
If cboReportingSupervisor2.Value = "" Then
MsgBox ("Please enter the name of the supervisor reporting the resumption.")
cboReportingSupervisor2.SetFocus
Exit Sub
End If
If txtMedical = "" Then
MsgBox ("Please give any details of any medication they may be taking, and/or any restrictions on the duties they can perform on resumption.")
txtMedical.SetFocus
Exit Sub
End If
ResumptionValid = True
End Sub
Private Sub cmdOK_Click()
Dim Sickness As Long
Dim Name, Location, Reason, SickShift, Duration, Resumption, Cover, Medication, Comments, Supervisor As String
Sickness = 4
Found = False
ExistingSickness = False
Do Until Found = True
If Sheets("Sickness").Cells(Sickness, 1).Text = txtSicknessID.Value Then
ExistingSickness = True
Found = True
Else
If Sheets("Sickness").Cells(Sickness, 1) = "" Then Found = True Else Sickness = Sickness + 1
End If
Loop
Validation
If Valid = False Then
Exit Sub
Else
PAYENumber = Format(Right(Left(cboEmployee.Value, (Len(cboEmployee.Value) - 1)), 5), "#####")
EmployeeName = Right(Left(cboEmployee.Value, (Len(cboEmployee.Value) - 8)), (Len(cboEmployee.Value) - (InStr(cboEmployee.Value, ",") + 9))) & Left(cboEmployee.Value, InStr(cboEmployee.Value, ",") - 1)
'Resumption data is filled in first to avoid entering partially complete sickness information,
'or having to test chkUFN twice.
If chkUFN.Value = True Then
ResumptionValidation
If ResumptionValid = False Then
Exit Sub
Else
With Sheets("Sickness")
.Cells(Sickness, 14) = Now
.Cells(Sickness, 15) = cboReportingSupervisor2.Value
.Cells(Sickness, 16) = txtTime2
.Cells(Sickness, 17) = Format(txtResumptionDate, "d mmm yy")
.Cells(Sickness, 18) = txtResumptionShift
.Cells(Sickness, 19) = cboResumptionLocation
.Cells(Sickness, 20) = txtMedical
.Cells(Sickness, 21) = txtComments
End With
End If
End If
If ExistingSickness = False Then
With Sheets("Sickness")
.Cells(Sickness, 1) = Sickness - 3
.Cells(Sickness, 2) = PAYENumber
.Cells(Sickness, 3) = EmployeeName
.Cells(Sickness, 4) = lblLocation.Caption
.Cells(Sickness, 5) = Now
.Cells(Sickness, 6) = cboReportingSupervisor.Value
.Cells(Sickness, 7) = txtTime.Value
.Cells(Sickness, 8) = txtShiftDate.Value
.Cells(Sickness, 9) = txtShiftTime.Value
.Cells(Sickness, 10) = cboLocation
.Cells(Sickness, 11) = txtReason
.Cells(Sickness, 12) = txtCoverArranged
.Cells(Sickness, 13) = txtExpectedDuration
End With
End If
Load frmEmailSickness
If ExistingSickness = True Then
frmEmailSickness.txtSubject.Value = "Resumption: " & frmReportSickness.cboEmployee.Value
SickShift = ""
Cover = ""
Resumption = "Resuming: " & frmReportSickness.txtResumptionShift & " on " & Format(frmReportSickness.txtResumptionDate.Value, "ddd dd mmm") & " at " & frmReportSickness.cboResumptionLocation.Value & Chr(10)
Medication = "Medication/Restricted Duties: " & frmReportSickness.txtMedical.Value & Chr(10)
Comments = "Comments: " & frmReportSickness.txtComments.Value & Chr(10)
Supervisor = Chr(10) & frmReportSickness.cboReportingSupervisor2.Value
Else
frmEmailSickness.txtSubject.Value = "Sickness: " & frmReportSickness.cboEmployee.Value
SickShift = "Shift: " & frmReportSickness.txtShiftTime.Value & " on " & Format(frmReportSickness.txtShiftDate.Value, "ddd dd mmm") & " at " & frmReportSickness.cboLocation.Value & Chr(10)
If frmReportSickness.chkUFN.Value = False Then
If frmReportSickness.txtExpectedDuration.Value = "" Then
Duration = "Expected Duration: No details at present." & Chr(10)
Else
Duration = "Expected Duration: " & frmReportSickness.txtExpectedDuration & Chr(10)
End If
Else
Duration = ""
End If
If frmReportSickness.chkUFN.Value = True Then
Resumption = "Resuming: " & frmReportSickness.txtResumptionShift & " on " & Format(frmReportSickness.txtResumptionDate.Value, "ddd dd mmm") & " at " & frmReportSickness.cboResumptionLocation.Value & Chr(10)
Else
Resumption = ""
End If
Cover = "Cover Arranged: " & frmReportSickness.txtCoverArranged.Value & Chr(10)
Medication = ""
Comments = ""
If frmReportSickness.chkUFN.Value = True Then
Medication = "Medication/Restricted Duties: " & frmReportSickness.txtMedical.Value & Chr(10)
Comments = "Comments: " & frmReportSickness.txtComments.Value & Chr(10)
Else
Medication = ""
Comments = ""
End If
Supervisor = Chr(10) & frmReportSickness.cboReportingSupervisor.Value
End If
Name = "Name: " & frmReportSickness.cboEmployee.Value & Chr(10)
Location = "Location: " & frmReportSickness.lblLocation.Caption & Chr(10)
Reason = "Reason: " & frmReportSickness.txtReason.Value & Chr(10)
frmEmailSickness.txtMessageBody.Value = Name & Location & Reason & SickShift & Duration & Resumption & Cover & Medication & Comments & Supervisor
frmReportSickness.Hide
frmEmailSickness.Show
Unload frmReportSickness
End If
End Sub
Private Sub cmdResume_Click()
Validation
If Valid = False Then Exit Sub
If chkUFN = False Then chkUFN.Value = True
MultiPage1.Pages("pgeresumesickness").Enabled = True
If MultiPage1.Value < 1 Then MultiPage1.Value = MultiPage1.Value + 1
txtResumptionDate.SetFocus
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub