Option Explicit
Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Private mlngTimerID As Long
Private emailAddress As String
Public Sub TimerCallBack(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
'TIMER FUNCTION
Dim myOLApp As New Outlook.Application
Dim myOLItem As Outlook.mailItem
Set myOLItem = myOLApp.CreateItem(olMailItem)
With myOLItem
.To = emailAddress
.Subject = "Time Untill Close"
.Body = "This is the time: " & Time & " So theres " & 60 - Minute(Now) & " Minutes Left to work"
.Send
End With
End Sub
Public Sub cmdStartTimer_Click()
Dim lngInterval As Long
lngInterval = Interval(cbinterval.Text, txttime.Text)
emailAddress = txtemailAddress.Text
If emailAddress = vbNullString Then Exit Sub
If lngInterval = Null Then Exit Sub
mlngTimerID = SetTimer(0, 0, lngInterval, AddressOf TimerCallBack)
MsgBox "Timer set!!"
End Sub
Private Sub cmdStopTimer_Click()
KillTimer 0, mlngTimerID
End Sub
Private Function Interval(intvl As String, length As Long) As Long
If intvl = "min" Then
Interval = length * 60000
ElseIf intvl = "hour" Then
Interval = length * 3600000
ElseIf intvl = "day" Then
Interval = length * 86400000
Else
MsgBox "something went wrong with calc interval"
End If
End Function