Condividi tramite

invio email con allegato pdf

Anonimo
2018-12-26T17:30:08+00:00

Buona sera a tutti.

Chiedo cortesemente se qualcuno di voi mi può aiutare.

Ho una maschera dove ho inserito vari dati, nella quale ho creato un pulsante per inviare una email.

il pulsante , mi apre un report, lo trasforma in pdf e lo salva in una cartella dove ho il Db., e  in base ad indirizzo email che ho in una casella di testo ( txtemail ) nella maschera  mi invia l'email.

Questo è il codice Pulsante :

Private Sub Comando60_Click()

DoCmd.OpenReport "STAMPA ISTRUZIONE", acViewPreview, , "ID=" & Me!ID

DoCmd.OutputTo acReport, "STAMPA ISTRUZIONE", acFormatPDF, CurrentProject.Path & "\PDF ADDESTRAMENTO CENTRALE" & "PDF ADDESTRAMENTO CENTRALE.PDF", False

DoCmd.Close acReport, "STAMPA ISTRUZIONE"

With Me.txtemail

 If Len(.Value & vbNullString) = 0 Then

   .BackColor = vbRed

    VBA.MsgBox prompt:="ATTENZIONE INSERIRE INDIRIZZO EMAIL !!!", _

           buttons:=vbCritical + vbYesNo, _

           title:="Informazione"

    .BackColor = vbWhite

    Exit Sub

 End If

End With

Dim OutApp As Object    ' late binding

Dim OutMail As Object  ' late binding

Dim strMsg As String ' contiene il testo del messaggio

Dim strDest As String ' contiene l'indirizzo email

Set OutApp = CreateObject("Outlook.Application")

Set OutMail = OutApp.CreateItem(0) ' creo una email vuota

strDest = txtemail

With OutMail

 .To = strDest

 .CC = ""

 .BCC = ""

 .Subject = "avviso"

 .HTMLBody = strMsg

 .Send

VBA.MsgBox prompt:=" EMAIL INVIATA !!!!", _

           buttons:=vbInformation, _

           title:="Informazione"

End With

Set OutMail = Nothing

Set OutApp = Nothing

End Sub

Ora vi chiedo come posso fare per allegare il report (trasformato in pdf ),cosa devo aggiungere nel codice?

grazie.

Pierluigi.

Microsoft 365 e Office | Accesso | Per la casa | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento

4 risposte

Ordina per: Più utili
  1. Anonimo
    2018-12-27T10:39:22+00:00

    Ciao Carlo.

    Mi succede che se invio email senza allegato la invia subito,

    con allegato invece devo aprire Outlook per inviarla, me la mette in posta in uscita.

    Secondo te sto usando il metodo corretto.

    ciao Carlo.

    Grazie.

    Pierluigi

    0 commenti Nessun commento
  2. Anonimo
    2018-12-27T09:44:55+00:00

    Hai scitto erroneamente

    .Attachments.Add StrCurrentProject.Path & "\PDF ADDESTRAMENTO CENTRALE" & "PDF ADDESTRAMENTO CENTRALE.PDF"

    il codice corretto è

    .Attachments.Add CurrentProject.Path & "\PDF ADDESTRAMENTO CENTRALE" & "PDF ADDESTRAMENTO CENTRALE.PDF"

    0 commenti Nessun commento
  3. Anonimo
    2018-12-27T09:29:55+00:00

    Ciao Carlo

    Ho aggiunto questa riga di codice:

    .Attachments.Add StrCurrentProject.Path & "\PDF ADDESTRAMENTO CENTRALE" & "PDF ADDESTRAMENTO CENTRALE.PDF"

    Private Sub Comando60_Click()

    DoCmd.OpenReport "STAMPA ISTRUZIONE", acViewPreview, , "ID=" & Me!ID

    DoCmd.OutputTo acReport, "STAMPA ISTRUZIONE", acFormatPDF, CurrentProject.Path & "\PDF ADDESTRAMENTO CENTRALE" & "PDF ADDESTRAMENTO CENTRALE.PDF", False

    DoCmd.Close acReport, "STAMPA ISTRUZIONE"

    With Me.txtemail

     If Len(.Value & vbNullString) = 0 Then

       .BackColor = vbRed

        VBA.MsgBox prompt:="ATTENZIONE INSERIRE INDIRIZZO EMAIL !!!", _

               buttons:=vbCritical + vbYesNo, _

               title:="Informazione"

        .BackColor = vbWhite

        Exit Sub

     End If

    End With

    Dim OutApp As Object    ' late binding

    Dim OutMail As Object  ' late binding

    Dim strMsg As String ' contiene il testo del messaggio

    Dim strDest As String ' contiene l'indirizzo email

    Set OutApp = CreateObject("Outlook.Application")

    Set OutMail = OutApp.CreateItem(0) ' creo una email vuota

    strDest = txtemail

    With OutMail

     .To = strDest

     .CC = ""

     .BCC = ""

     .Subject = "avviso"

     .HTMLBody = strMsg

    .Attachments.Add StrCurrentProject.Path & "\PDF ADDESTRAMENTO CENTRALE" & "PDF ADDESTRAMENTO CENTRALE.PDF"

    .Attachments.Add Str C:\Users\Terry\Desktop\PROGRAMMA ADDESTRAMENTO - ISTRUZIONE\PDF ADDESTRAMENTO CENTRALE

    .Send

    VBA.MsgBox prompt:=" EMAIL INVIATA !!!!", _

               buttons:=vbInformation, _

               title:="Informazione"

    End With

    Set OutMail = Nothing

    Set OutApp = Nothing

    End Sub

    il Percorso file pdf è questo :

    C:\Users\Terry\Desktop\PROGRAMMA ADDESTRAMENTO - ISTRUZIONE\PDF ADDESTRAMENTO CENTRALE

    ma non riesco a farlo funzionare.

    ciao Carlo.

    grazie

    Pierluigi

    0 commenti Nessun commento
  4. Anonimo
    2018-12-26T19:30:46+00:00

    ...

    .Attachments.Add strPercorsoFile

    ...

    .Send

    0 commenti Nessun commento