Una famiglia di sistemi di gestione per database relazionali di Microsoft progettati per semplificare l'uso.
ciao Andrea,
prendo spunto dai link che ti ho suggerito, con qualche minima personalizzazione.
modifica la tua form in questo modo, modificando anche la tabella in modo che il controllo fullPath sia associato :
inserisci i command button carica pdf che chiamerai cmdLoadPdfFile e mail! che chiamerai cmdInvioEmail.
Ovviamente ulteriormente customizzabili.
l'evento clicl del command button carica pdf ha questo codice :
Private Sub cmdLoadPdfFile_Click()
Me.FullPath = cmdFileDialog()
End Sub
quello dell'invio email questo invece :
Private Sub cmdInvioEmail_Click()
If Len(Me.Invio_Mail & vbNullString) = 0 Then
VBA.MsgBox "indirizzo email non completato!", vbCritical, "Attenzione"
Exit Sub
End If
If Len(Me.FullPath & vbNullString) = 0 Then
VBA.MsgBox "allegato non presente!", vbCritical, "Attenzione"
Exit Sub
End If
Dim strMessaggio As String
Dim strSubject As String
strMessaggio = "Gentile " & Me.ID_Clienti.Column(1) & vbNewLine & _
" in allegato l'avviso di pagamento" & vbNewLine & _
" Distinti Saluti."
strSubject = "Invio avviso al" & str(Time)
CreateEmailWithOutlook Me.Invio_Mail, strSubject, strMessaggio, Me.FullPath
End Sub
inserisci questo in due moduli standard :
mod_invio email :
Option Compare Database
Option Explicit
Private outLookIstance As Object 'Outlook.Application
Public Function CreateEmailWithOutlook( _
ByVal MessageTo As String, _
ByVal Subject As String, _
ByVal MessageBody As String, _
ByVal strFile As String)
' Define app variable and get Outlook using the "New" keyword
Dim olMailItem As Object ' Outlook.MailItem ' An Outlook Mail item
' Create a new email object
newOlIstance
Set olMailItem = outLookIstance.CreateItem(0)
' Add the To/Subject/Body to the message and display the message
With olMailItem
.To = MessageTo
.Subject = Subject
.Body = MessageBody
.Display ' To show the email message to the user
.Attachments.Add strFile
End With
' Release all object variables
Set olMailItem = Nothing
Set outLookIstance = Nothing
End Function
Private Sub newOlIstance()
On Error Resume Next
Set outLookIstance = GetObject(, "Outlook.Application")
If outLookIstance Is Nothing Then
Set outLookIstance = CreateObject("Outlook.Application")
End If
End Sub
mod_fileDialog :
Option Compare Database
Option Explicit
Private Const strPathRete As String = "C:\prova"
Public Function cmdFileDialog() As Variant
Dim fDialog As Object
Dim varFile As Variant
Set fDialog = Application.FileDialog(3)
With fDialog
.Title = "Select One or More Files"
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "files PDF", "*.pdf"
.InitialFileName = CurrentProject.Path & ""
If .Show = True Then
varFile = .SelectedItems(1)
Else
varFile = Null
End If
End With
cmdFileDialog = varFile
End Function
al click del command button cmdLoadPdfFile sceglierai il file da allegare, a quello del cmdInvioEmail creerai l'email allegando il file scelto.
ciao, Sandro.