Question : Access to read info from query and send out results in excel

Hello:

I have a code that reads info from a query and then sends it out the results as text within the body of an email, and loops thru the registers from different sales people. But instead of sending it as text, I would prefer to send out the query results in excel and then have that excel file be attached and sent to the associated salesperson. How can I do this?

thanks.
Joseph
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
Private Sub Form_Open(Cancel As Integer)

On Error GoTo SMError
    
    Dim rs As DAO.Recordset
    Dim db As Database
    'Opens recordset, reads all the emails note this query reads the values from the field called EmailAddr, table tblEmails
    Set db = CurrentDb
    Set rs = db.OpenRecordset("SELECT EmailAddr, TextoCom FROM info_ped_presup_tot")
    Dim textEmail, textEmailOT As String
    Dim Email As String
        
     
    Email = ""
    textEmailOT = ""
    
    
    'Goes through the list of records returned by the above call
    Do While Not rs.EOF

        Email = rs!EMailAddr
        textEmail = "Informe de pedidos que se abrieron en el mismo periodo del año pasado con su presupuesto asociado y a partir de ahí todos los presupuestos que se enviaron a clientes durantes los 45 días siguientes a partir de hoy." & Chr(13) & Chr(10) & Chr(13) & Chr(10)
        textFooter = "Esta información os servirá para tener mejor visión de posibles operaciones que se estén gestionando y no dejar pasar oportunidades." & Chr(13) & Chr(10)
        textFirma = "CRM Goldmine"
        Do While Email = rs!EMailAddr
                        
             textEmail = textEmail & rs!TextoCom & Chr(13) & Chr(10)
             rs.MoveNext
             If rs.EOF Then Exit Do
            'Send to email address read from the database (field is rs!EmailAddr)
            'Subject is Auto Send
             'Body Text is "This is a test of an auto send"
        Loop
        DoCmd.SendObject acSendNoObject, , , Email, , "[email protected]", "Informe de Pedidos/Presup del Año Anterior", textEmail & Chr(13) & Chr(10) & textFooter & Chr(13) & Chr(10) & textFirma, False
        textEmailOT = textEmailOT & textEmail & Chr(13) & Chr(10) & Chr(13) & Chr(10)
        'Read next record
        'rs.MoveNext
        
    Loop

    'Close and clear all
    rs.Close
    Set rs = Nothing
    Set db = Nothing
    'If textEmailOT <> "" Then DoCmd.SendObject acSendNoObject, , , "[email protected]", , , "ABC", textEmailOT, False
    

    DoCmd.RunMacro ("cerrarform")
    
        
    Exit Sub

SMError:

Answer : Access to read info from query and send out results in excel

Try this:

Change .Port = 465 to .Port = 587 or .Port = 25

 This should work.

 587 is the Outgoing server (SMTP) port for IMAP. It uses a TLS
encryption connection.

 465 is the Outgoing server (SMTP) port for pop. It uses an SSL
encryption connection.             


I found it from here: clikc to see
Random Solutions  
 
programming4us programming4us