I have query;this code work but i have 2 little problems:
1) i want send 1 mail
2) every query is attached so "qdf.pdf" but i'd like to get is real name
Code:
Private Sub Comando5_Click()
On Error GoTo err:
Dim VDb As DAO.Database
Dim qdf As QueryDef
Const msg = “testo"
Set VDb = CurrentDb
Dim outApp As Outlook.Application, outMsg As MailItem
Set outApp = CreateObject("Outlook.Application")
Set outMsg = outApp.CreateItem(olMailItem)
If VDb.QueryDefs.Count > 0 Then
For Each qdf In CurrentDb.QueryDefs
If qdf.Name = "Q_TipoDestinazDiv" Then
Debug.Print qdf.Name
Else
If DCount("*", qdf.Name) > 0 Then
DoCmd.OutputTo acQuery, qdf.Name, acFormatPDF, "C:\Documents and Settings\junior\Desktop\Controlli\" & qdf.Name
With outMsg
.Importance = olImportanceHigh
.SendUsingAccount = outApp.Session.Accounts.Item(1)
.ReadReceiptRequested = True ' conferma lettura
.OriginatorDeliveryReportRequested = True ' conferma recapito
.To = "xxx@tiscali.it"
.CC = " yyy@tiscali.it "
'.BCC = " ccc@tiscali.it "
.Subject = "oggetto"
.Body = msg
.Attachments.Add ("C:\Documents and Settings\ junior \Desktop\Controlli\qdf.pdf")
‘.Display
.Send
End With
End If
End If
Next qdf
End If
Set outApp = Nothing
Set outMsg = Nothing
err:
If err > 0 Then
MsgBox (err.Description & " " & err.Number)
End If
err.Clear
End Sub