473,421 Members | 1,736 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,421 software developers and data experts.

Send Current Object to PDF

NeoPa
32,556 Expert Mod 16PB
Hello everyone.

I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).

I know it can be done by selecting :
  1. External Data (Ribbon)
  2. PDF or XPS (from the Export Group)
  3. Select all desired options
  4. Publish
That's fine, but how to get this done in VBA?

I want to be clear that I don't need (or even want really) a whole bunch of code that does the whole job for me. I just need a pointer to what Method of DoCmd (or whatever) can be used to get this done. I am though, happy to sift through any code for the nugget if that's what you have to offer.

Last, but not least, I've suggested elsewhere that all new questions should come with isladogs' Access/Windows/Office365 Version Checker info attached, so here's mine :

Expand|Select|Wrap|Line Numbers
  1. Access / Windows / Office Version Info
  2. Date/Time:              15/10/2023 17:56:25
  3. Workstation Name:       BELLPC10
  4. Operating System:       Windows 10 Enterprise Version 22H2 - Build 10.0.19045.3448 64-bit
  5. Access Full Version:    Access 2019 Version 2308 - Build 16.0.16731.20234 64-bit
  6. Access Path:            C:\Program Files\Microsoft Office\root\Office16\
  7. Office 365 Installed:   No
  8. Office Install Method:  Click-to-Run
  9. Update Channel:         Not applicable
All offerings are received gratefully, as I appreciate any time expended regardless of how successfully helpful it may prove.
Oct 15 '23 #1

✓ answered by DJRhino

NeoPa,

Expand|Select|Wrap|Line Numbers
  1. Dim strReportName   As String
  2. Dim myReportWhere   As String
  3. Dim myOutPutFile    As String
  4. strReportName = Replace(Replace("REJECT TAG#|1 PN |2", "|1", Nz(" " & [REJECT TAG NUMBER], " ")), "|2", Nz([Part Number] & " " & [Descriptive Reason], " "))
  5.  
  6. myReportWhere = "[REJECT TAG NUMBER] = [Forms]![Reject Tag Form Edit]![REJECT TAG NUMBER]"
  7.  
  8. DoCmd.OpenReport "Reject Tag Report", acViewPreview, , myReportWhere
  9.  
  10. myOutPutFile = "M:\Inspect\New Reject Tag Database\Reports" & "\" & strReportName & ".PDF"
  11.  
  12. DoCmd.OutputTo acOutputReport, "Reject Tag Report", acFormatPDF, myOutPutFile, False, acExportQualityPrint
  13.  
  14. DoCmd.Close acReport, "Reject Tag Report", acSaveNo
This is how I do it...Sample of the code I use...Hope this is what you were looking for....

4 37020
DJRhino
106 64KB
NeoPa,

Expand|Select|Wrap|Line Numbers
  1. Dim strReportName   As String
  2. Dim myReportWhere   As String
  3. Dim myOutPutFile    As String
  4. strReportName = Replace(Replace("REJECT TAG#|1 PN |2", "|1", Nz(" " & [REJECT TAG NUMBER], " ")), "|2", Nz([Part Number] & " " & [Descriptive Reason], " "))
  5.  
  6. myReportWhere = "[REJECT TAG NUMBER] = [Forms]![Reject Tag Form Edit]![REJECT TAG NUMBER]"
  7.  
  8. DoCmd.OpenReport "Reject Tag Report", acViewPreview, , myReportWhere
  9.  
  10. myOutPutFile = "M:\Inspect\New Reject Tag Database\Reports" & "\" & strReportName & ".PDF"
  11.  
  12. DoCmd.OutputTo acOutputReport, "Reject Tag Report", acFormatPDF, myOutPutFile, False, acExportQualityPrint
  13.  
  14. DoCmd.Close acReport, "Reject Tag Report", acSaveNo
This is how I do it...Sample of the code I use...Hope this is what you were looking for....
Oct 16 '23 #2
NeoPa
32,556 Expert Mod 16PB
Hi Rhino.

It actually is what I was looking for. I was preparing a post to say "Thank you, but no." as it's something I already found & checked, but the secret (that I totally missed) was that it could, after all, be used to work with the active object as long as the [ObjectName] parameter is left blank. (And, as I subsequently discovered, even when it's not. See post #5)

So thank you. You've pointed me in the right direction, and for that I'm grateful :-)
Oct 16 '23 #3
DJRhino
106 64KB
NeoPa,

Glad I could help, whether Directly or indirectly. This site has helped me so much.

Rhino
Oct 16 '23 #4
NeoPa
32,556 Expert Mod 16PB
Hi Rhino.

As a follow on, because I know this can cause issues for people sometimes, I would just explain that when used with [ObjectName:="Something" (or even just passing it as the second parameter, as you have - which is [ObjectName]), and that object name happens to refer to an object that is already open in your Access window, whether currently selected or otherwise, what will be output is the version of the object that is already open.

So, if you have a report called rptA, and this report is based on a table (called tblB) with 100 records and you execute the following code without first opening rptA, you will see the full report including each of the 100 records :
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.OutputTo(ObjectType:=acOutputReport _
  2.                   , ObjectName:="rptA" _
  3.                   , OutputFormat:=acFormatPDF _
  4.                   , OutputFile:="C:\Temp\rptA.Pdf" _
  5.                   , AutoStart:=True)
However, if first you open rptA for preview, and filter it such that only two records are included, then regardless of how many, or which, other objects you open as well, executing the code above will, instead, show just what you can see in the preview on the screen.

In case there are any who are so unused to using or seeing procedure calls done using the named parameters as I have shown above, here is a version that makes exactly the same call, but using positional parameters instead :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acOutputReport, "rptA", acFormatPDF, OutputFile:="C:\Temp\rptA.Pdf", True
Oct 16 '23 #5

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

Similar topics

5
by: AC | last post by:
I have the need to destory the current object when a method is called. Such as: public class Animal{ public string animalType = string.Empty; public void Delete(){ this = null; } }
2
by: Ricardo Luceac | last post by:
Hi... I'm new to c# network programing, and I only find a way to send plain text over the network, but I need to send an object... Does someone know how do I send this object??? s...
3
by: hariharan.priya | last post by:
I am a beginner working with STLs I need to delete the current object in the queue. Which container provides this function? and which algorithm should i use? Thank you
1
by: ron | last post by:
Does anybody know how to implement the functionality of sending the current page by email? IE does provide the function: Tools->Mail and News->Send Page... Thanks!
1
by: =?Utf-8?B?Tmljaw==?= | last post by:
Hi all, i have a webpage with a button and click button to generate a word document, which take about 10 second. so what i am trying to do is i write a javascript to display a message to...
3
by: barkarlo | last post by:
I made a report who has many pages. Now,I would like send current page in a report (like attachment) to Microsoft office outlook, but i do'nt know. I tried , but always send all pages from a...
5
by: damezumari | last post by:
How do I let the user send the current html page they are on as the message in an email? I know how to send emails with php, but not how I let the current page be the message. I want to do...
2
by: O.B. | last post by:
I have a class that has an Explicit StructLayout. In the constructor below, I am copying data from a byte array onto this class so as to initialize all the explicit attributes of the class. What...
4
by: DocBlack4444 | last post by:
Good Afternoon, I have searched for a few days and found older fixes to this problem but nothing that is current to my version of Access (365) or current to the type of code that i am working...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
1
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...
0
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,...

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.