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

ComboBox Selection to PDF

37 32bit
I am trying to save a report to a PDF file based on a Combobox selection of reports, but can't figure out
how to place a combobox selection into a docmd.output line of code?

Ex:
Replace "Summary" with a Combobox selection, this way I'm not hardcoding report names.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acOutputReport, "Summary", acFormatPDF, "C:\Reports" & ".pdf"
And can it also be used as a selection in a case statement? Case 1, 2 and 4 are working in my project.
Case 1
Print Report
Case 2
View Report
Case 3
Expand|Select|Wrap|Line Numbers
  1.  DoCmd.OutputTo acOutputReport, "Summary", acFormatPDF, "C:\Reports" & ".pdf"
Case 4
Email Report

Any ideas?

Thank you
Nov 8 '22 #1

✓ answered by NeoPa

Hi Curious.

Have a look at the two lines of code. First, the one I posted :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acOutputReport, {ComboBoxRef}.Value, acFormatPDF, "C:\Reports.pdf"
and then your own attempt at applying that :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acOutputReport, "cboPrintReports.value", acFormatPDF, "C:\Reports" & ".pdf"
Did you notice the differences?

The second is more obvious but doesn't cause a problem with the code - it just indicates a lack of understanding of what you're doing & why. "C:\Reports" & ".pdf" & "C:\Reports.pdf" both produce exactly the same result. The first is just complicating matters for no reason.

The more important issue is that you've converted a reference to a string (, {ComboBoxRef}.Value,), into an actual string of that reference (, "cboPrintReports.value",), which completely obliterates its use as a reference. In your case it should probably be , cboPrintReports.Value,. Maybe you've already come up with that solution already.

10 6574
NeoPa
32,556 Expert Mod 16PB
Hi Curious.

Simply use a reference to the ComboBox control on your form.

EG.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acOutputReport, {ComboBoxRef}.Value, acFormatPDF, "C:\Reports.pdf"
Nov 8 '22 #2
Curious27
37 32bit
Hi NeoPa

Doing good I hope.

I had already tried that before I posted but my mistake was I was trying cboPrintReport.Column(1) and that obviously didn't work. I tried your suggestion with .Value and that was a error also. The error is a Run-time error '2501': The OutputTo action was created. When I click Debug it shows my line of code as follows.
Expand|Select|Wrap|Line Numbers
  1.  DoCmd.OutputTo acOutputReport, "cboPrintReports.value", acFormatPDF, "C:\Reports" & ".pdf"
Nov 8 '22 #3
isladogs
455 Expert Mod 256MB
Windows blocks files being saved to the root c:\ drive and cancels the operation resulting in error 2501
Try saving to another allowed folder e.g. your MyDocuments folder
Nov 8 '22 #4
Curious27
37 32bit
Looked to see if the file path may be wrong but it is correct. I did try one thing I removed the file path completely all the way up to acFormatPDF even the comma and the code run through, the File Explorer popped up with the title "Output To" and the report name was what I selected.
I clicked OK and the report was saved as a PDF file and I opened it in Acrobat.

Why is the file path a problem and why is the extension ".pdf" needed as acFormatPDF already assigns this extension?

Going bald from scratching my head to much...
Nov 8 '22 #5
Curious27
37 32bit
isladogs

That path doesn't work either, as my original path looks like this: "C:\Users\Administrator\Documents\Access Databases\Reports". That path is were my Access Database is and all the Access Security Trust Center Setting are pointed to this path along with it's Subfolders.
I even tried sending to D:\Reports with no luck.

Thanks for looking at it.
Nov 8 '22 #6
Curious27
37 32bit
I found out what may the one problem.

The problem is a lazy rookie programmer (ME), I copied this code from a report I created a while back which I placed a Command Button on to convert to a PDF so I could eMail. Well being in a rush and not reviewing what I copied, I just found this Dim statement buried at the top.

Expand|Select|Wrap|Line Numbers
  1. Dim fileName As String, fldrPath As String, filePath As String
Not supposed to be there. PERIOD.
Nov 8 '22 #7
isladogs
455 Expert Mod 256MB
Hi
Glad you have a solution
In answer to your earlier questions:
a) MS blocks applications saving to certain folders for various reasons including
- folders considered vital to Windows operating correctly e.g. c:\Windows\System32
- the root folder c:\ - I think this is to ensure that contains as few files as possible to speed up Windows loading times...but I may be wrong
b) Using acFormatPDF ensures the file is saved as a PDF file. It doesn't provide the file extension
Specifying the file suffix as .pdf ensures Windows will open it with the default application for PDF files e.g. Acrobat or your web browser.
You could use any file suffix you like e.g. .XYZ but then Windows will ask you what application to open it with!

Hope that helps clarify things
Nov 8 '22 #8
NeoPa
32,556 Expert Mod 16PB
Hi Curious.

Have a look at the two lines of code. First, the one I posted :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acOutputReport, {ComboBoxRef}.Value, acFormatPDF, "C:\Reports.pdf"
and then your own attempt at applying that :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acOutputReport, "cboPrintReports.value", acFormatPDF, "C:\Reports" & ".pdf"
Did you notice the differences?

The second is more obvious but doesn't cause a problem with the code - it just indicates a lack of understanding of what you're doing & why. "C:\Reports" & ".pdf" & "C:\Reports.pdf" both produce exactly the same result. The first is just complicating matters for no reason.

The more important issue is that you've converted a reference to a string (, {ComboBoxRef}.Value,), into an actual string of that reference (, "cboPrintReports.value",), which completely obliterates its use as a reference. In your case it should probably be , cboPrintReports.Value,. Maybe you've already come up with that solution already.
Nov 8 '22 #9
Curious27
37 32bit
NeoPa
I did catch that part of the cmbPrintReports.

Well, removing that Dim statement did nothing for my problem. I have a Report where I put a command button on to save it as a pdf file and the file path is identical to the one I'm having an issue with. Running that code saves the report as a pdf an places it in the same folder and I can't figure out why. The only difference is the code behind the command button contains a Dim statement as follows, Dim fldrPath As String.

My question is do I need a Dim statement for this path and if so how would I reference it in the DoCmd statement?
Nov 8 '22 #10
Curious27
37 32bit
I figured it out.

I changed the code a little to include these Dim's.
Expand|Select|Wrap|Line Numbers
  1. Dim fileName As String, fldrPath As String, filePath As String
Then added a different way to get the file path to work.
Expand|Select|Wrap|Line Numbers
  1.     fileName = Me.cboPrintReports.value
  2.     fldrPath = "C:\Reports"
  3.     filePath = fldrPath & "\" & fileName & ".pdf"
Then Case 3
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acOutputReport, cboPrintReports.value, acFormatPDF, outputFile:=filePath
And yes it writes to the C:\ root directory.

Just needed someone to talk it out with, thank you guys.
Nov 9 '22 #11

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

Similar topics

2
by: jen | last post by:
i have select query that returns multiple records and populates a combobox/pulldown. once a selection from the pulldown is selected, i need to reference two or three fileds from the previous...
4
by: Mtek | last post by:
Hi, We have a combo box on our page, which gets populated via a MySQL Query in PHP. What we want to do is to print the values on the page in a table that correspond the to selection from the...
1
by: Rosie | last post by:
I have a main form with header info w/ 'tHeader' as the control source. I have a subform with 'tDetail' as a control source. They're strung together by a field named MA_ID. This works...
0
by: pavanip | last post by:
Hi, I am facing problem with combobox in gridview.I have used combobox in gridview and i am binding data to gridview combobox from database. If i click 2 times on combobox then it is showing the...
1
by: Emily Walshaw | last post by:
I'm sorry, I know this has been asked a million times, but am completely new to access and need idiot proof help. I have a database and I am struggling to get a field to update based on a combobox...
0
by: Moorthi chinna | last post by:
how to reload combobox in datagridview based on combobox selection in datagridview?
4
Seth Schrock
by: Seth Schrock | last post by:
I have a database that is keeping track of returned mail. Each piece of returned mail has a status. I want to be able to view reports for all the returned mail in each status. I could create a...
10
by: simaonobrega | last post by:
Dear Bytes community, Framework: I have created a form using the "Form Design" tool. On the form property sheet, it was added to the Record Source the table which contained the fields that I...
2
by: ERG1982 | last post by:
Hi all, I need to combine the action of a command button to be dependent on the selection in the Combo Box in order to fill the cell with the selection that the combo box refers to. For...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
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...

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.