473,698 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Save Access Report Automatically after printing to PDF

2 New Member
Hi!

First off, bear with me; I've just started to learn VBA and this is my first post on this site. My question could be extremely basic, but I haven't been able to find anything via the internet that fits my needs exactly.

I need a way to save a report to a specific path after I have printed it as a PDF, so that I can send it as an email attachment. The idea is that an associate would be able to press a button and the report would print to PDf and send. I have the printing and the email code, but where I'm stuck is that I don't know how to save the report automatically to a path after using the PDF Printer. Right now it prints but then opens a "Save As" dialogue box. I'd like it to print and then save itself to a path.

This is the code I'm using at the moment to print the report:


Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_Click()
  2.  
  3. Dim defPrinter As String, NewPrinter As Printer
  4.  
  5. defPrinter = Application.Printer.DeviceName
  6.  
  7. Set NewPrinter = Application.Printers("Nationwide PDF Printer")
  8.  
  9. Set Application.Printer = NewPrinter
  10.  
  11. DoCmd.OpenReport "Weekly Application Status Update", acViewNormal
  12.  
  13. DoCmd.Close acReport, "Weekly Application Status Update", acSaveNo
  14.  
  15. Set NewPrinter = Application.Printers(defPrinter)
  16. Set Application.Printer = NewPrinter
  17. End Sub
  18.  
Thanks in advance!
Feb 10 '15 #1
2 4526
jforbes
1,107 Recognized Expert Top Contributor
I think if you are using a Print Driver to generate the PDF, you are at the mercy of the Print Driver when it comes to it's options. So if it has a way to automatically save to a directory based on a settings file or something similar then that is the route you will need to take.

If you are using Access 2007 or newer, you can use DoCmd.OutputTo to have Access create the PDF for you and use the options that is supplies to save the PDF to a hard drive.

Here is some code from a project I worked on recently:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport sReportName, acViewPreview, , "ID='" & sID & "'"
  2. DoCmd.OutputTo acOutputReport, "", acFormatPDF, sFileName, True
  3. DoCmd.Close acReport, sReportName
In my example, I supply a Filter for the Report. Which requires opening the report first and then outputting to a PDF instead of just producing the output. The Report could be based on a Query to Filter the Report records and then the above code would be simpler, but there were other reasons that I decided against it.

So if you don't need to Filter on open, which it doesn't look like you do, you should be able to getaway with just the single DoCmd.OutputTo command; something like this:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acOutputReport, "Weekly Application Status Update", acFormatPDF, sFileName, True
Feb 10 '15 #2
nalongar
2 New Member
That worked like a dream! And so simple too! Thank you for the help!
Feb 11 '15 #3

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

Similar topics

3
23875
by: Nicola | last post by:
Hi Everyone, I am new to programming and would like to know how to open an access Report from within vb 6. I am trying to write a program to organise cross stitch threads. I have found out how to use a database table but all I want to do now is to click a command button to display this access report. Any suggestions please ?????
15
13321
by: Mark C | last post by:
All, I have exhaustingly been looking through the newsgroups in search of a way to systemically output an Access 97 report to a pdf file using the full version of Adobe Acrobat. I want the user to be able to click a button and have the Access report saved as a pdf in a directory specified by me the programmer. I have seen a posting by John Baker promoting a web-sight that has an mde that one can reference in any database but after 30...
1
3018
by: mar10a | last post by:
I am trying to insert a .gif. file into an Access report - using Insert Picture. The original image is 8X11, but access changes the size to 4X6.5. When I change the size of the image in access is puts white border around it and does not change the actual image. Is there a setting I need to change that would allow access to import at the correct size, or do I need to use another file type besides
0
2726
by: neoteny2 | last post by:
I need MS Access to automatically create reports/subreports based on specific criteria. I am building a database in Access 2003 with different locations/sites. I have the "sites" table created containing site info, including an empty field for "date". I also have a report format already created displaying the site info. I need Access to ask the user for a date, calculate three additional dates using the entered date (adding or subtracting...
1
22773
by: ellenh | last post by:
I have read postings on the similar subject including the posting from 2003 shown below. This process works fine to display a single page snapshot report in PowerPoint. I need to display subsequent pages from the same snapshot file in subsequent slides in PowerPoint. I realize that it is possible to add VB code to the Snapshot Viewer Control and that there are properties such as .FirstPage, .NextPage, .LastPage, etc, But I can't find...
3
7491
by: Birky | last post by:
I have a report which I am opening from a command button within a form. I am using the “DoCmd.OpenReport stDocName” command to open the report but it is automatically printing instead of popping the report to the screen. How can I stop it from printing and just have the output sent to the screen? Any help would be greatly appreciated. Thanks Birky
6
5224
by: DeniseY | last post by:
I have an Access report that is created on the fly by the user selecting the fields to be included. The Access report comes out fine, but I want it to automatically output to an Excel spreadsheet. Again, I have this part working. But the fields in the resulting spreadsheet are in a different order than the Access report. (Example: The fields in the Access report might go FirstName, LastName,Address,City--in the Excel spreadsheet, they come up...
1
2492
by: sonicfun2006 | last post by:
I have SQL Server Database and MS Access 2003 is connected with ODBC. I have very large amount of records in various tables. The database is very dynamic as it changes every minute. I’m trying to have a live MS Access report which would pull data from SQL Server. I’ll try to explain how I’m trying do this: The Access report should have two parts: 1. Title page report, just like table of contents. It should be listing a particular field of a...
1
6248
by: billelev | last post by:
Here is some code that I have adapted slightly. It allows a report to be printed to a specific location. It works by calling SaveReportAsPDF and specifying the access report name, and the root directory to which the filename should be saved. The routine adjusts registry values to achieve its aim. Now, it works, but not quite as I would like it. I originally thought that I would be able to adjust a registry key (such as...
3
7684
by: Bay0519 | last post by:
Hi, I'm using access 2003. Is there a way for me to open an access report with zoom to 82% automatically? Right now, I set it up as maximize, using docmd.maximize but I want it to zoom to 82% for users to be able to see all the data clearly when they open the report. Please help. Thank you in advance.
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9164
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8898
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7734
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3051
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.