Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send email using a timer

Status
Not open for further replies.

netrusher

Technical User
Feb 13, 2005
952
US
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
 
You could use a form to run the code and so take advantage of the Timer Event. The Timer Interval can be set to zero programatically when the system time matches a set end time. Alternatively, you could use the Windows Sheduler with a shortcut to Access that includes a /x switch, or some vbscript.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top