Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsDate(TextBox1.Value) Then
TextBox1.Value = vbNullString
Else
TextBox1.Tag = CDate(TextBox1.Value)
Select Case CDate(TextBox1.Tag)
Case Is <= 1
TextBox1.Value = Format(TextBox1.Value, "hh:mm")
Case Is > 1
TextBox1.Value = Format(TextBox1.Value, "dd/mm/yyyy hh:mm")
End Select
If TextBox1.Value <> "" And TextBox2.Value <> "" Then CalculateValues
End If
End Sub
Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsDate(TextBox2.Value) Then
TextBox2.Value = vbNullString
Else
TextBox2.Tag = CDate(TextBox2.Value)
Select Case CDate(TextBox2.Tag)
Case Is <= 1
TextBox2.Value = Format(TextBox2.Value, "hh:mm")
Case Is > 1
TextBox2.Value = Format(TextBox2.Value, "dd/mm/yyyy hh:mm")
End Select
If TextBox1.Value <> "" And TextBox2.Value <> "" Then CalculateValues
End If
End Sub
Private Sub TextBox3_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1.Value <> "" And TextBox2.Value <> "" Then CalculateValues
End Sub
Private Sub TextBox4_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1.Value <> "" And TextBox2.Value <> "" Then CalculateValues
End Sub
Private Sub TextBox5_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1.Value <> "" And TextBox2.Value <> "" Then CalculateValues
End Sub
Private Sub CalculateValues()
Dim startDate As Date
Dim startHours As Double
Dim endDate As Date
Dim endHours As Double
Dim numHours As Double
Dim numDays As Long
TextBox3.Value = vbNullString
Select Case True
Case CDate(TextBox2.Tag) < CDate(TextBox1.Tag)
TextBox3.Value = "Stop before Start "
Case Is = CDate(TextBox2.Tag) = CDate(TextBox1.Tag)
TextBox3.Value = "Stop same as Start "
Case Else
startDate = CDate(TextBox1.Text) \ 1
startHours = CDate(TextBox1.Text) - startDate
endDate = CDate(TextBox2.Text) \ 1
endHours = CDate(TextBox2.Text) - endDate
numHours = IIf(startHours > endHours, 1, 0) + (endHours - startHours)
numDays = endDate - startDate - IIf(startHours > endHours, 1, 0)
If numDays > 0 Then TextBox3.Value = TextBox3.Value & Format(numDays, "0 ""DAY(S)""")
TextBox3.Value = TextBox3.Value & Format(numHours, " h:mm ""HOURS""")
TextBox4.Value = numDays
TextBox5.Value = Format(numHours, "hh:mm ""HOURS""")
End Select
End Sub