Unfortunately I'm on Access 2003 and that won't work as is. Is there a way to get this to work with 2003?
Main Topics
Browse All TopicsI have an Access database that I have created a form where the user can check multiple reports and when I press a button I need it to export each as a PDF. Here's the catch. I want the user to be able to select a folder location on the form, and when the button is pressed I need code or a macro to specify the path and a new filename, and save each report respectively without prompting the "Save PDF As" dialog.
Example:
User puts a check next to rpt1 and rpt2, and enters s:\jobNumber\ in the path location.
they click the Create PDF Button
Each report is automatically created and saved as shown below without any additional interaction from the user:
s:\jobNumber\RenamedReport
s:\jobNumber\RenamedReport
I do not want to modify registry entries or have to relly on outside .dll files to do this. There are shared databases that are used by multiple users, so the solution must be self contained...
Hopefully all that makes sense. Any ideas?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I don't know if this will work. If it doesn't, please post your code.
Private Sub PrintPdf_Click()
Dim strPdfWriterPath As String
Dim strFilePath As String
Dim strJob As String
Dim strAccessRptName As String
'Open File
'strPdfWriterPath is the path to the application object (your pdf writer e.g. adobe.exe)
'strFilePath is the path to the pdf file
strPdfWriterPath = "C:\Program Files\Adobe\Acrobat 5.0\Acrobat\Acrobat.exe"
strFilePath = "s:\" & strJob & strAccessRptName & ".pdf"
Call Shell(strPdfWriterPath & " " & strFilePath, vbMaximizedFocus)
End Sub
oops! left out the variable assignments for the Job and ReportName
Private Sub PrintPdf_Click()
Dim strPdfWriterPath As String
Dim strFilePath As String
Dim strJob As String
Dim strAccessRptName As String
'Open File
'strPdfWriterPath is the path to the application object (your pdf writer e.g. adobe.exe)
'strFilePath is the path to the pdf file
strPdfWriterPath = "C:\Program Files\Adobe\Acrobat 5.0\Acrobat\Acrobat.exe"
strJob = Me.txtJob 'assumed textbox on report launcher
strAccessRptName = Me.txtjRptTitle
strFilePath = "s:\" & strJob & strAccessRptName & ".pdf"
Call Shell(strPdfWriterPath & " " & strFilePath, vbMaximizedFocus)
End Sub
DoeSmith,
1. You have asked a question that requires that you be familiar with VBA coding
2. <I'm on Access 2003>
The you need to invest in one or the may "Convert to PDF" utilities that there are out there.
I use this:
http://www.lebans.com/repo
3. <User puts a check next to rpt1 and rpt2>
A multiselect Listbox is the more accepted method of doing this, because it require no modifications when reports are Added, Renames, Deleted, ...etc
4. <enters s:\jobNumber\ in the path location.>
The problem with this is that a lot of users will simply type: C:\SomeFolder", forgetting the ending "\"
(thinking that is is presumed, or does not matter)
c:\YourFolder
....is *Not* the same as:
c:\YourFolder\
Entering "c:\YourFolder" will result in a file in the c: root folder named "YourFolderYourReportName.
So now (in addition to *everything* else), you must add validation for the ending "\".
Here is a fully functional sample.
You will have to modify it to work in your database.
You also must download the Dll from the link and install it into the same folder as the DB will reside in.
http://www.lebans.com/Down
The path was incorrect, but when I fixed it, it opens Acrobat, but gives me the error file not found.
I'm on acrobat 8.
here's the code I'm using to test it:
Private Sub Command50_Click()
Dim strPdfWriterPath As String
Dim strFilePath As String
Dim strJob As String
Dim strAccessRptName As String
'Open File
'strPdfWriterPath is the path to the application object (your pdf writer e.g. adobe.exe)
'strFilePath is the path to the pdf file
strPdfWriterPath = "C:\Program Files\Adobe\Acrobat 8.0\Acrobat\Acrobat.exe"
strJob = "999" 'assumed textbox on report launcher
strAccessRptName = "CA Letter 05-09"
strFilePath = "c:\" & strJob & strAccessRptName & ".pdf"
Call Shell(strPdfWriterPath & " " & strFilePath, vbMaximizedFocus)
End Sub
Apparently, the Shell command is looking for the file to open it, but can't find it because it has not been saved. Try the code as modifiied and see if it works. I think you might need to set a vb library reference to Accrobat.
Private Sub Command50_Click()
'Declare variables representing the objects to be manipulated
Dim PDFdoc As New AcroPDDoc
Dim strPdfWriterPath As String
Dim strFilePath As String
Dim strJob As String
Dim strAccessRptName As String
'_________________________
'initialize the object variables
'_________________________
'strPdfWriterPath is the path to the application object (your pdf writer e.g. adobe.exe)
'strFilePath is the path to the pdf file
strPdfWriterPath = "C:\Program Files\Adobe\Acrobat 8.0\Acrobat\Acrobat.exe"
strJob = "999" 'assumed textbox on report launcher
strAccessRptName = "CA Letter 05-09"
strFilePath = "c:\" & strJob & strAccessRptName & ".pdf"
'_________________________
'save, then open the report created in Access to pdf
'_________________________
PDFdoc.Save & " " & strFilePath
Call Shell(strPdfWriterPath & " " & strFilePath, vbMaximizedFocus)
End Sub
Place your form in design view, then go to the code editor window. Once you are in the vb code editor, go to the Access command menu and select Tools>references. First, look at the screen and see if it says if there are any missing references; then scroll down the reference list for the Adobe 8 reference, select it and select ok.
When I try that I get a type mismatch. I did some digging and saw someone's code with it having a 1, before the filename like this:
PDFdoc.Save 1, strFilePath
When I do that I get a file not found in acrobat. If I put it like this:
PDFdoc.Save (1, strFilePath)
I get a syntax error. I'm not getting any intellisence
This is where I am so far. I also modified he 1st 2 lines of code:
Private Sub Command50_Click()
'Declare variables representing the objects to be manipulated
Dim PDFdoc As Object
Set PDFdoc = New AcroPDDoc
'Dim PDFdoc As New AcroPDDoc
Dim strPdfWriterPath As String
Dim strFilePath As String
Dim strJob As String
Dim strAccessRptName As String
'_________________________
'initialize the object variables
'_________________________
'strPdfWriterPath is the path to the application object (your pdf writer e.g. adobe.exe)
'strFilePath is the path to the pdf file
strPdfWriterPath = "C:\Program Files\Adobe\Acrobat 8.0\Acrobat\Acrobat.exe"
strJob = "999" 'assumed textbox on report launcher
strAccessRptName = "CA Letter 05-09"
strFilePath = "c:\" & strJob & strAccessRptName & ".pdf"
'_________________________
'save, then open the report created in Access to pdf
'_________________________
PDFdoc.Save 1, strFilePath
Call Shell(strPdfWriterPath & " " & strFilePath, vbMaximizedFocus)
End Sub
Ok, So I changed the binding so I have intellisencs now. Here are the methods that intellisencs shows for PDFdoc. (no SaveAs)
AquirePage
ClearFlags
Close
Create
CreateTextSelect
CreateThumbs
CropPages
DeletePages
DeleteThumbs
GetFileName
GetFlags
GetInfo
GetInstanceID
GetJSObject
GetNumPages
GetPageMode
GetPermanantID
InsertPages
MovePage
Open
OpenAVDoc
ReplacePages
Save
SetFlags
SetInfo
SetPageMode
Just got back on-line. Now that you have intellisense, try typing;
PDFdoc.Save As
or
PDFdoc.Save
or
PDFdoc.GetFileName strAccessReportName
and see what pops up on intellisense.
Re: early binding, you declare what library files are needed and Access makes them available during the coding phase. Late binding, Access determines what reference libraries are needed at runtime.
Business Accounts
Answer for Membership
by: puppydogbuddyPosted on 2009-08-14 at 12:13:53ID: 25101396
Assuming you are using the Access 2007 pdf add-in, all you need to do is store the Access report name and jobNumber in variables, for example strAccessRptName and strJob as shown in folllowing code behind a button.
Private Sub YourButton_Click()
DoCmd.OutputTo acOutputReport, strAccessRptName, acFormatPDF, "s:\" & strJob & strAccessRptName & ".pdf", False
End Sub