473,387 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Create multiple Pdf's from records in a report and email pds's

547 512MB
I have a query = qryCyclistCard2a
Report = rptCyclistEntries
Unique field - RaceNo (number field)
The report shows one record per page with many fields
Each of these pages needs to be converted to a Pdf based on the strReportname.
The email field also appears on every page of the report and each pdf document.
Can i create a Pdf document and then email it to the email address listed together with RaceNo field on each page
Please assist.This is driving me insane after 3 days.
An attachment shows the report page that is converted to Pdf
Problem -its not functioning now


Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rs As DAO.Recordset
  3. Dim RecordSetString As String
  4. Dim stDocName As String
  5. Dim strUserName As String, strPath As String
  6. Dim strReportname As String
  7. strPath = "C:\Pdf\"
  8. strUserName = [Reports]![rptCyclistEntries]![RaceNo]
  9. strReportname = "Race_Number" + "--" + strUserName + "--" & Format(Date, "dd-mm-yyyy") + ".pdf"
  10.  
  11. RecordSetString = rptCyclistEntries.RecordSource
  12. Set db = CurrentDb
  13. Set rs = CurrentDb.OpenRecordset(RecordSetString)
  14.  
  15. rs.MoveFirst
  16. With rs
  17. Do While Not rs.EOF
  18.  
  19.     stDocName = "rptCyclistEntries"
  20.  
  21.      DoCmd.OpenReport "rptCyclistEntries", acViewPreview, , "[RaceNo] = " & ![RaceNo]
  22.  
  23.         DoCmd.OutputTo acOutputReport, "", acFormatPDF, strPath + strReportname, False
  24.         DoCmd.close acReport, "rptCyclistEntries"
  25.  
  26. .MoveNext
  27. Loop
  28. End With
  29. rs.close
  30. Set rs = Nothing
Attached Images
File Type: jpg pdf.jpg (70.9 KB, 410 views)
Jul 1 '14 #1
6 1692
twinnyfo
3,653 Expert Mod 2GB
neelsfer,

I think you have the right concept here.

First, you say
Problem -its not functioning now
Exactly what is not functioning, so we know where to start.....

Second, there are two basic ways to do what you are doing. The first way, as it appears you are trying to do, is to create the PDF attachments and to save them. However, according to your code (Line 23) you will be overwriting your PDFs, as you are not changing the file name. Perhaps the following:

Line 9:

Expand|Select|Wrap|Line Numbers
  1. strReportname = "Race_Number" + "--" & _
  2.     strUserName & "--" & Format(Date, "dd-mm-yyyy")
Then, Line 23:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acOutputReport, "", acFormatPDF, _
  2.     strPath & strReportname & ![RaceNo] & ".pdf", False
The other way to do it (if you have the e-mail addresses available in your db) is to use the SendObject method, including the e-mail addresses, making sure that the Report is filtered by the Race Number in your recordset.

Will be glad to help, if we get some more information on what is not working.
Jul 2 '14 #2
neelsfer
547 512MB
Thx Twinnyfo i fiddled with the code and it tells me now - "compile error variable not defined" and hangs

What i want to do:
take each individual page in the report and export it to an individual pdf using
Expand|Select|Wrap|Line Numbers
  1. strReportname = "Race_Number" + "--" + strUserName + "--" & Format(Date, "dd-mm-yyyy") + ".pdf"
I then also use the email field in this "qryCyclistCard2a" query as the record source of the "rptCyclistEntries" report, and send an email to the individual persons listed on each report page.
I imagine i will probably have to use something like this to email in the code:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.SendObject acSendReport, "rptCyclistEntries" acFormatPDF, rs!Email, , , "TestMessage Title", "Race Entries", True
thx for your assistance so far

I attach a mini version of what i have done in Access 2007 to assist you. create a c:\pdf folder to export
Attached Files
File Type: zip export Pdf_issue.zip (579.9 KB, 73 views)
Jul 2 '14 #3
twinnyfo
3,653 Expert Mod 2GB
For your error, it looks like you Dim MyDB, but you set the variable db, so that could be the initial source of your problem.
Jul 2 '14 #4
twinnyfo
3,653 Expert Mod 2GB
Concerning the sending of the e-mails, if you are able to produce a one-page report for each race results, then you should be able to build code to cycle through the races, then cycle through the e-mail addresses in your query, building the various parts of your e-mail.

Your second block of code is exactly the direction you want to go (don't forget the comma before acFormatPDF).

Play around with your code sequences. Let us know if you hit any more snags and we will try to trouble shoot to a solution.

Hope this helps!
Jul 2 '14 #5
neelsfer
547 512MB
Twinnyfo
I have changed direction to prevent spam emails getting blocked, as it is send to numerous persons.

1. open a continious form with all the recipients in different rows
2. add a button on the left of row that is named "email"
3. create a personalised Pdf file in a specific folder
4. take this file and put it into the "Outbox" of the email with the To:, subject etc added, and the file attached.
5. delete file from folder
The code i am using:
Expand|Select|Wrap|Line Numbers
  1. Function SendFiles(fldName As String, Optional FileType As String = "*.*")
  2.  
  3. Dim appOutLook As Outlook.Application
  4.     Dim MailOutLook As Outlook.MailItem
  5.     Dim strPath As String
  6.     Dim strFilter As String
  7.     Dim strFile As String
  8.  
  9.     strPath = "C:\Pdf\"      'Edit to your path
  10.     strFilter = "*.Pdf"
  11.     strFile = Dir(strPath & strFilter)
  12.  
  13.     If strFile <> "" Then
  14.  
  15.         Set appOutLook = CreateObject("Outlook.Application")
  16.         Set MailOutLook = appOutLook.CreateItem(olMailItem)
  17.  
  18.         With MailOutLook
  19.             .BodyFormat = olFormatRichText
  20.             .To = [Forms]![frmExportEntries]![email]
  21.             ''.cc = ""
  22.             ''.bcc = ""
  23.             .Subject = "Race Entry"
  24.             .HTMLBody = "Please print out this Race Entry Form in good quality, and take with to the race. It will speed up your entry."
  25.             .Attachments.add (strPath & strFile)
  26.             .Send
  27.             '.Display    'Used during testing without sending (Comment out .Send if using this line)
  28.         End With
  29.     Else
  30.         MsgBox "No file matching " & strPath & strFilter & " found." & vbCrLf & _
  31.                 "Processing terminated."
  32.        ' Exit Sub    'This line only required if more code past End If
  33.     End If
  34.  
  35. End Function
The rest of the code to rename the Pdf file and call the function
Expand|Select|Wrap|Line Numbers
  1. On Error GoTo Command99_Click_Err
  2. Dim strUserName As String, strPath As String
  3. Dim strReportname As String
  4. Dim OutApp As Outlook.Application
  5. Dim OutMail As Outlook.MailItem
  6. Set OutApp = CreateObject("Outlook.Application")
  7. Set OutMail = OutApp.CreateItem(olMailItem)
  8. Dim strbody As String
  9. Dim attachmentname As String
  10. Dim myAttachments As String
  11.  
  12.  
  13. Me.Email_Sent.Value = "-1"
  14. 'rptCyclistEntries
  15. DoCmd.OpenReport "rptCyclistEntries", acPreview
  16. strPath = "C:\Pdf\"
  17. strUserName = [Reports]![rptCyclistEntries]![RaceNo]
  18. strReportname = "Race_Number" + "-" + strUserName + "-" & Format(Date, "dd-mm-yyyy") + ".pdf"
  19.  
  20. DoCmd.OutputTo acOutputReport, "", acFormatPDF, strPath + strReportname, False
  21. DoCmd.close acReport, "rptCyclistEntries"
  22.  
  23. '-------------
  24. Call SendFiles("C:\Pdf\")
  25.  
  26. Kill "C:\pdf\*.pdf"
  27.  
Thanks for your assistance. I hope this code also helps somebody else to email reports in Pdf.
Attached Images
File Type: jpg email entries.jpg (33.2 KB, 193 views)
Jul 3 '14 #6
twinnyfo
3,653 Expert Mod 2GB
neelsfer,

Glad we coudl get you in the right direction for a solution!
Jul 3 '14 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: anmar | last post by:
I'm trying to figure out how to select all the records in one table which have multiple specified records in a second table. Here's a simplified version of my problem. I have two tables,...
2
by: ME | last post by:
I need to know how to create a MULTI page report. All I can seem to create is a report with only one page, even though the datasource it is bound to returns multiple records. I have posted an...
2
by: krissh | last post by:
I know How Excel sheet in php .But wat i want is how to create Multiple sheets in Excel . This is the code for creating one excel sheet <?php header('Content-type:application/ms-xls'); ...
0
by: cannonpm | last post by:
Greetings and salutations. I have developed an A2K3 MDB and have a search form modeled after Allen Browne's search form (http:// allenbrowne.com/ser-62.html). It works well except for records which...
1
by: colin-whitehead | last post by:
I have 2 tables tblReports primary key UPN, plus numeric fields Effort, Attain, etc tblComments numeric primary key ID & textfield Text In the Query I select each record from tblReports...
3
by: DeanL | last post by:
Hi guys, Does anyone know of a way to create multiple tables using information stored in one table? I have a table with 4 columns (TableName, ColumnName, DataType, DataSize) and wanted to know...
2
by: muddasirmunir | last post by:
I want to know a good tool/software , to create fillable PDFs forms , in addition to adobe, which is not to heavy (heavy means not take much space or not too big in size) I had just tried this...
1
by: kffacs | last post by:
Multiple rows based on a date range I have an MSAccess 2007 DB to record our employees Personal Days Off (PDO). Until now I have only had a form to record each single day taken. This results in...
3
zmbd
by: zmbd | last post by:
Chapter 2 of the Z’s Saga or: The Curious Difference Between what the Union Query Returns and what the Report Prints Prolog: This is where I started as there was what I thought a good solution...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.