Below is the code I have attached to a Command Button that sends a query by email. I was wondering if this action could be put on a timer to automatically send the query by email based on the timer? Also could the Timer be set up to only perform the action part of the day, say from 7am until 1am?
Code:
Private Sub OneThreeCurrentFaults_Click()
SendMail1
End Sub
Sub SendMail1()
Dim clsSendObject As accSendObject
Dim strMsg As String
Dim SL As String, DL As String
Dim emailsubject As String
Dim emailtext As String
Dim toEmail As String
Dim QAclerk As String
SL = vbNewLine
DL = SL & SL
toEmail = "ENG(BER); QA(BER); STAFF(BER); FAB(BER); ASSEMBLY(BER)"
emailsubject = "FTT Current WU Faults 1-3Ton"
QAclerk = DLookup("[UserName]", "UserNameTBL", "[LogonName] = '" & GetCurrentUserName() & "'")
If QAclerk = "Kimberly Casteel" Then
emailtext = Now() & DL & _
"Everyone:" & DL & _
"Attached is the current days Work Unit Faults Spreadsheet for your review" & DL & _
"Thank you," & DL & _
QAclerk & SL & _
"Quality Assurance" & SL & _
"NMHG.Berea , KY" & SL & _
"859 986-6205"
Else
If QAclerk = "Sharon Zulick" Then
emailtext = Now() & DL & _
"Everyone:" & DL & _
"Attached is the current days Work Unit Faults Spreadsheet for your review" & DL & _
"Thank you," & DL & _
QAclerk & SL & _
"Quality Assurance" & SL & _
"NMHG.Berea , KY" & SL & _
"859 985-5781"
Else
If (QAclerk <> "Kimberly Casteel" Or QAclerk <> "Sharon Zulick") Then
emailtext = Now() & DL & _
"Everyone:" & DL & _
"Attached is the current days Work Unit Faults Spreadsheet for your review" & DL & _
"Thank you," & DL & _
QAclerk & SL & _
"Quality Assurance" & SL & _
"NMHG.Berea , KY"
End If
End If
End If
Set clsSendObject = New accSendObject
strMsg = String(3000, "a")
clsSendObject.SendObject acSendQuery, "EmailCurrentOneThreeCurrentDayWUFaultsTotalsQry", accOutputXLS, _
toEmail, , , emailsubject, emailtext, True
Set clsSendObject = Nothing
End Sub