DoCmd.Sendobject can't make it work properly

Gand114

Registered User.
Local time
Today, 12:01
Joined
Apr 21, 2016
Messages
15
Hi to everyone!
I ve already got help here on my project (thanks Paul!) and as a total newbe I need you help once again.

Below here there is the code that generates about a 100 ratesheets for my customers. This works great.
Basically I get all the pdf ratesheets Saved with the proper name (customer name + my company name ecc.) in the folder of my choice.

Next what i wanted to do is to have those sent to each relevant recipient via E-mail.
The matter is I have no idea on how to do it, I found docmd.send object to put right after docmd.output to, but then I get the report sent basically empty and without the correct filename.
Any idea on what i can do? I ve been trying to search but i only bumped into pretty complicate stuff which i dunno where to start with...

Code:
Private Sub Comando1_Click()

Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim rs As New ADODB.Recordset
rs.activeconnection = cnn1
rs.Open "[soloragsoc]"
 Dim ragsoc As String
Dim pafi As String
Dim file As String
Dim path As String
Dim db As Database
Dim ingragsoc As String
Dim repName As String
repName = "newreport"
ragsoc = "[Q_Retrieve nolo export]![ragione sociale]"


 pafi = path & file
 If Not rs.EOF Then
rs.MoveFirst
Do While Not rs.EOF
ingragsoc = rs.Fields(0)
path = "C:\Users\diego.macaluso\Desktop\EXEPE"
file = "\Listino Tetris Consolidation export Maggio 2016" & " " & ingragsoc & ".pdf"
Dim fulpafi As String
fulpafi = path & file

'from now on it generates the ratesheet file based on customer name in the recordset


DoCmd.OpenReport repName, acViewPreview, , "[QQ_Retrieve nolo export]![ragione sociale] ='" & ingragsoc & "'"
DoCmd.OutputTo acOutputReport, , acFormatPDF, fulpafi
DoCmd.Close acReport, repName
 rs.MoveNext
 Loop
End If
rs.Close
Set rs = Nothing
Set db = Nothing
 End Sub

Thanks for any suggestion you can think of!
Ciao
 
Hello,

DoCmd.SendObject is one method. The correct syntax is:
DoCmd.SendObject acSendReport,ReportName,Format,To,CC,BCC,Subject,Message Text,Edit
so in your case probably;
DoCmd.SendObject acSendReport, repName, acFormatPDF,Addresses to send to, CC?,BCC?, "Listino Tetris Consolidation export Maggio 2016" & " " & ingragsoc, Message,True
 
Dear Isskint,
first of all thanks a lot.
It works indeed, but I still have an issue:
see, when Access creates and save the file :

Code:
 DoCmd.OpenReport repName, acViewPreview, , "[QQ_Retrieve nolo export]![ragione sociale] ='" & ingragsoc & "'"
DoCmd.OutputTo acOutputReport, , acFormatPDF, fulpafi
It does is correctly naming it according to the Customer name:

i.e.
"Listino Tetris Consolidation export Maggio 2016 mycustomer.pdf"

When instead it attaches the file to email:

Code:
 DoCmd.OpenReport repName, acViewPreview, , "[QQ_Retrieve nolo export]![ragione sociale] ='" & ingragsoc & "'"
DoCmd.SendObject acSendReport, repName, acFormatPDF, maiadd, , , "Listino Tetris Consolidation export Maggio 2016" & " " & ingragsoc, "Test message ratesheet", True
DoCmd.Close acReport, repName
The attached file is named:
"NewReport.pfd" (NewReport being the name of the report in access)

Is there any way to have it named differently (or to rename it before it gets attached)?

Thanks a lot in advance on this!
 

Users who are viewing this thread

Back
Top Bottom