Automatically attach query as Excel Spreadsheet to email

aldeb

Registered User.
Local time
Today, 16:13
Joined
Dec 23, 2004
Messages
318
Below is an example of how I send email from a command button. I would like to attach a query to this email as an Excel Spreadsheet. I know how to send queries as Excel Spreadsheets but can anyone tell me how to attached a Query to the Email automatically as an Excel File?

Code:
Private Sub OneThreeCurrentFaults_Click()

SendMail1

End Sub

Sub SendMail1()

       
       DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

       Dim clsSendObject As accSendObject
       Dim strMsg As String
       Dim emailsubject As String
       Dim emailtext As String
       Dim SL As String, DL As String
       Dim toemail As String
      
       SL = vbNewLine
       DL = SL & SL
       
       emailsubject = "Please see attached Current Work Unit Faults Spreadsheet for 1-3T Line"
       
       emailtext = Now() & DL & _
       "Please see attached Excel Spreadsheet showing today's Work Unit Faults" & DL & _
       "Thank You,"

       toemail = "abhwinte@nmhg.com"

       Set clsSendObject = New accSendObject
       strMsg = String(3000, "a")
       clsSendObject.SendObject , , accOutputrtf, _
       toemail, , "abajacks@nmhg.com", emailsubject, emailtext, True
       Set clsSendObject = Nothing


End Sub
 
This is what worked! Thanks for all suggestions!

Code:
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

            SL = vbNewLine
            DL = SL & SL

            emailsubject = "Please see attached Current Work Unit Faults Spreadsheet for 1-3T Line"
            
            emailtext = Now() & DL & _
            "This is a test" & DL & _
            "regards," & DL & _
            "Kimberly Casteel" & SL _
            
       Set clsSendObject = New accSendObject
       strMsg = String(3000, "a")
       clsSendObject.SendObject acSendQuery, "OneThreeCurrentDayWUFaultsTotalsQry", accOutputXLS, _
         "abajacks@nmhg.com", , , emailsubject, emailtext, True
       Set clsSendObject = Nothing
       
    End Sub
 
Anyone:

Is there a way to attached two Queries to an email? With the code above I have attached one Query.
 

Users who are viewing this thread

Back
Top Bottom