ok... what have I missed.. it's not quite working.
Code:
Dim cDateTime As Date
Dim FirstSunday1 As Date
Dim FirstSunday2 As Date
Dim d As Date
Dim w As Integer
d = DateSerial(Year(Date), 4, 1)
w = Weekday(d, vbSunday)
FirstSunday1 = d + IIf(w, 8 - w, 0)
d = DateSerial(Year(Date), 10, 1)
w = Weekday(d, vbSunday)
FirstSunday2 = d + IIf(w, 8 - w, 0)
cDateTime = Date
If cDateTime >= FirstSunday1 And cDateTime <= FirstSunday2 Then
If [StateID] = 4 Then
cDateTime = Time()
ElseIf [StateID] = 5 Then
cDateTime = DateAdd("n", -30, Time())
ElseIf [StateID] = 8 Then
cDateTime = DateAdd("h", -2, Time())
ElseIf [StateID] = 3 Then
cDateTime = DateAdd("n", -30, Time())
Else
cDateTime = Time()
End If
ElseIf cDateTime >= FirstSunday2 And cDateTime <= FirstSunday1 Then
If [StateID] = 4 Then
cDateTime = DateAdd("h", -1, Time())
ElseIf [StateID] = 5 Then
cDateTime = DateAdd("n", -30, Time())
ElseIf [StateID] = 8 Then
cDateTime = DateAdd("h", -3, Time())
ElseIf [StateID] = 3 Then
cDateTime = DateAdd("n", -90, Time())
Else
cDateTime = Time()
End If
End If
Me.txtTimeBox.Value = cDateTime