Condividi tramite

Modificare il nome dell'allegato

Anonimo
2020-04-13T17:49:54+00:00

Buongiorno e Buona Pasqua a tutti

visto che dobbiamo restare in casa ne approfitto per lavorare per cui parte la richiesta di aiuto.

Probabilmente per voi esperti di Access sarà una cosa semplice ma, per un neofita come me diventa una cosa complicatissima, veniamo al problema.

Attraverso una macro di Access sono riuscito ad allegare un report alla mail da inviare, vi riporto lo schema utilizzato per la macro:

L'allegato alla mail prende il nome dal nome assegnato alla Etichetta nella scheda Formato delle proprietà del Report, in pratica avendo assegnato a questa il nome "Ordine", il report allegato alla mail prende il nome di "Ordine.pdf".

La domanda è: è possibile fare in modo di aggiungere all'Etichetta "Ordine" anche il numero dell'ordine prendendolo direttamente dal campo NUM_ORDINE e magari anche la data?

Grazie a tutti per l'aiuto e ancora buona Pasqua a tutti

Ciro

Microsoft 365 e Office | Access | 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

12 risposte

Ordina per: Più utili
  1. Anonimo
    2020-04-14T11:18:28+00:00

    ciao Ciro,

    non si interviene nei reports per stampare e inviare via email.

    I reports non sono iterattivi anche se consentono di inserire command buttons.

    [….]

    agendo da un report non posso utilizzare il Me., devo per forza (credo) utilizzare lo "spaghetto code" come lo chiami tu, ho quindi modificato 

    […]

    me è il riferimento alla classe, i reports sono classi quindi me è assolutamente utilizzabile.

    Nella versione rivista non c'è lo spaghetti code.

    [….]

    Spero vada bene così, in ogni caso funziona, hai proposte migliori?

    […]

    altra cosa che non condivido è il basta che funzioni….quindi la seconda delle due sempre.

    Un saluto,

    Sandro.

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Anonimo
    2020-04-14T07:53:19+00:00

    Ciao Sandro

    no la form "ORDINE_MATERIALI" è la form dalla quale accedo al report dal quale posso stampare l'ordine o salvarlo in PDF, o inviarlo via mail, ad ogni modo ho apportato le tue modifiche solo che, agendo da un report non posso utilizzare il Me., devo per forza (credo) utilizzare lo "spaghetto code" come lo chiami tu, ho quindi modificato in:

    Private Sub cmdOUTLOOK_Click()

        On Error GoTo errHandler

        Dim strReport   As String

        Dim strMessage  As String

        Dim strAttName  As String

        Dim strReceiver As String

            If Forms![ORDINE_MATERIALI]![MAILORDINE] Then

               VBA.MsgBox prompt:="Lo stato dell'Ordine ? impostato su mail gi? inoltrata", _

                                   buttons:=vbInformation, _

                                   Title:="AVVISO"

               Exit Sub

            End If

        strReport = "R_ORDINE"  ' personalizza il nome del report

        strMessage = "Buongiorno, " & vbNewLine & _

                   "In allegato l'ordine in oggetto." & vbNewLine & _

                   "Distinti saluti."

        strAttName = "OrdineFornitore_N." & Me.NUM_ORDINE & "_dataOrdine_" & Me.DATAORDINE ' personalizza il nome dei controlli

        strReceiver = Me.MAIL 'MAIL ? il campo contenente l'indirizzo mail

        With DoCmd

            .OpenReport reportName:=strReport, _

                        view:=acViewPreview, _

                        windowMode:=acHidden

            Reports(strReport).Caption = strAttName

            .SendObject objectType:=acSendReport, _

                         objectname:=strReport, _

                         outputformat:=acFormatPDF, _

                         To:=strReceiver, _

                         Subject:=strAttName, _

                         messageText:=strMessage, _

                         editMEssage:=-1, _

                         TemplateFile:=0

        End With

    exitErr_handler:

                Forms![ORDINE_MATERIALI]![MAILORDINE] = True

                Forms![ORDINE_MATERIALI]![STATOORDINE] = "INOLTRATO"

                DoCmd.Close objectType:=acReport, _

                        objectname:=strReport

            Exit Sub

    errHandler:

                 With Err

                     Select Case Err

                         Case 2501

                                 VBA.MsgBox prompt:="Invio Annullato", _

                                 buttons:=vbInformation, _

                                 Title:="AVVISO"

                         Case Else

                                 VBA.MsgBox "ERR#" & .Number _

                                     & vbNewLine & .Description _

                                      , vbOKOnly Or vbCritical

                     End Select

                     Resume exitErr_handler

                 End With

    End Sub

    Spero vada bene così, in ogni caso funziona, hai proposte migliori?

    Ciao, Ciro

    La risposta è stata utile?

    0 commenti Nessun commento
  3. Anonimo
    2020-04-14T07:10:29+00:00

    ciao Ciro,

    lo spaghetti code anche no dai….

    questa --->Forms![ordine_materiali] è le form da cui si invia l'email ?

    Se si, vedi correzioni in grassetto:

    Private Sub cmdOUTLOOK_Click()

        On Error GoTo errHandler

    **if me.**MAILORDINE then

    vba.msgBox prompt:="Lo stato dell'Ordine ? impostato su mail gi? inoltrata", _

    buttons:=vbInformation, _

    Title:="AVVISO"

    exit sub

    end if

        Dim strReport   As String

        Dim strMessage  As String

        Dim strAttName  As String

        Dim strReceiver As String

        strReport = "R_ORDINE"  ' personalizza il nome del report

        strMessage = "Buongiorno, " & vbNewLine & _

                   "In allegato l'ordine in oggetto." & vbNewLine & _

                   "Distinti saluti."

        strAttName = "ordineFornitore_N." & Me.NUM_ORDINE & "_dataOrdine_" & Me.DATAORDINE ' personalizza il nome dei controlli

        strReceiver = Me.MAIL 'MAIL ? il campo contenente l'indirizzo mail

        With DoCmd

            .OpenReport reportName:=strReport, _

                        view:=acViewPreview, _

                        windowMode:=acHidden

            Reports(strReport).Caption = strAttName

            .SendObject objectType:=acSendReport, _

                         objectname:=strReport, _

                         outputformat:=acFormatPDF, _

                         To:=strReceiver, _

                         Subject:=strAttName, _

                         messageText:=strMessage, _

                         editMEssage:=-1, _

                         TemplateFile:=0

        End With

    exitErr_handler:

    with me

            .[MAILORDINE] = True

    .[STATOORDINE] = "INOLTRATO"

    end with

            DoCmd.Close objectType:=acReport, _

                        objectname:=strReport

            Exit Sub

    errHandler:

                 With Err

                     Select Case Err

                         Case 2501

                                 VBA.MsgBox prompt:="Invio Annullato", _

                                 buttons:=vbInformation, _

                                 Title:="AVVISO"

                         Case Else

                                 VBA.MsgBox "ERR#" & .Number _

                                     & vbNewLine & .Description _

                                      , vbOKOnly Or vbCritical

                     End Select

                     Resume exitErr_handler

                 End With

      End Sub

    ciao, Sandro.

    La risposta è stata utile?

    0 commenti Nessun commento
  4. Anonimo
    2020-04-14T06:57:35+00:00

    Ciao Sandro

    era proprio quello che cercavo, sapevo che era possibile solo utilizzando il VBA ma non riuscivo a trovare nulla che mi potesse aiutare per evitare di utilizzare le macro di access che, sebbene facilissime da utilizzare sono, troppo spesso molto limitate.

    sono riuscito ad introdurre anche i controlli per evitare di inviare due volte l'ordine al fornitore e a inserire automaticamente l'indirizzo mail, ti posto il codice:

    Private Sub cmdOUTLOOK_Click()

        On Error GoTo errHandler

        Dim strReport   As String

        Dim strMessage  As String

        Dim strAttName  As String

        Dim strReceiver As String

            If Forms![ordine_materiali]![MAILORDINE] = True Then

                MsgBox "Lo stato dell'Ordine ? impostato su mail gi? inoltrata", vbInformation, "ATTENZIONE!!!"

                GoTo AA

            Else

                Forms![ordine_materiali]![MAILORDINE] = True

                Forms![ordine_materiali]![STATOORDINE] = "INOLTRATO"

            End If

        strReport = "R_ORDINE"  ' personalizza il nome del report

        strMessage = "Buongiorno, " & vbNewLine & _

                   "In allegato l'ordine in oggetto." & vbNewLine & _

                   "Distinti saluti."

        strAttName = "ordineFornitore_N." & Me.NUM_ORDINE & "_dataOrdine_" & Me.DATAORDINE ' personalizza il nome dei controlli

        strReceiver = Me.MAIL 'MAIL ? il campo contenente l'indirizzo mail

        With DoCmd

            .OpenReport reportName:=strReport, _

                        view:=acViewPreview, _

                        windowMode:=acHidden

            Reports(strReport).Caption = strAttName

            .SendObject objectType:=acSendReport, _

                         objectname:=strReport, _

                         outputformat:=acFormatPDF, _

                         To:=strReceiver, _

                         Subject:=strAttName, _

                         messageText:=strMessage, _

                         editMEssage:=-1, _

                         TemplateFile:=0

        End With

    exitErr_handler:

            DoCmd.Close objectType:=acReport, _

                        objectname:=strReport

            Exit Sub

    errHandler:

                 With Err

                     Select Case Err

                         Case 2501

                                 VBA.MsgBox prompt:="Invio Annullato", _

                                 buttons:=vbInformation, _

                                 Title:="AVVISO"

                         Case Else

                                 VBA.MsgBox "ERR#" & .Number _

                                     & vbNewLine & .Description _

                                      , vbOKOnly Or vbCritical

                     End Select

                     Resume exitErr_handler

                 End With

    AA:

        End Sub

    Sei davvero un grande, sono fortunato ad aver trovato te come mentore!!!

    Grazie ancora e, a presto

    Ciro

    La risposta è stata utile?

    0 commenti Nessun commento
  5. Anonimo
    2020-04-13T19:04:08+00:00

    ciao Ciro,

    Buona Pasqua a te.

    Vedi se questo ti aiuta, modificando opportunamente le parti dove trovio la dicitura ' personalizza..... ect...

    Private Sub cmdEmail_Click()

    On Error GoTo errHandler

    Dim strReport   As String

    Dim strMessage  As String

    Dim strAttName  As String

    Dim strReceiver As String

    strReport = "reportOrdine"  ' personalizza il nome del report

    strMessage = "Buongiorno, " & vbNewLine & _

               "In allegato l'ordine in oggetto." & vbNewLine & _

               "Distinti saluti."

    strAttName = "ordineFornitore_N." & Me.numeroOrdine & "_dataOrdine_" & Me.DATAORDINE ' personalizza il nome dei controlli

    strReceiver = "******@pluto.com"

    With DoCmd

        .OpenReport reportName:=strReport, _

                    view:=acViewPreview, _

                    windowMode:=acHidden

        Reports(strReport).Caption = strAttName

        .SendObject objectType:=acSendReport, _

                     objectname:=strReport, _

                     outputformat:=acFormatPDF, _

                     to:=strReceiver, _

                     Subject:=strAttName, _

                     messageText:=strMessage, _

                     editMEssage:=-1, _

                     TemplateFile:=0

    End With

    exitErr_handler:

        DoCmd.Close objectType:=acReport, _

                    objectname:=strReport

        Exit Sub

    errHandler:

             With Err

                 Select Case Err

                     Case 2501

                             VBA.MsgBox prompt:="invio Annullato", _

                             buttons:=vbInformation, _

                             Title:="avviso"

                     Case Else

                             VBA.MsgBox "ERR#" & .Number _

                                 & vbNewLine & .Description _

                                  , vbOKOnly Or vbCritical

                 End Select

                 Resume exitErr_handler

             End With

    End Sub

    ciao, Sandro.

    La risposta è stata utile?

    0 commenti Nessun commento