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