[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2068
  • Last Modified:

Access Report code doesn't run with DoCmd.OutputTo acOutputReport

DoCmd.OutputTo acOutputReport, "rpt_summary1", acFormatPDF, PDFPATH & "\" & repName & ".pdf", True, , , acExportQualityPrint

The above code does make a PDF but there are several items on the report that are populated in the ONLoad event -e.g.
Private Sub Report_Load()
  Me.txt_fillMe1 = "Some Value"
  Me.txt_fillMe2 = "Some other Value"
'ect.
End Sub

The report runs perfect in print and preview

But when I use the above OutputTo the PDF is created but none of the controls that are populated in the reports code have anything in them
the code behind the report doesn't seem to run -

Funny thing is - Using the menu Item in Print Preview ribbon on the Data Tab PDF or XPS (this may be an add on by adobe- some confusion) - Anyway - This exports the PDF just fine - If I could do this Menu in VBA this would work
   
1
bczingo
Asked:
bczingo
  • 8
  • 7
1 Solution
 
omgangCommented:
Have you tried using an OnFormat event instead of OnLoad?

OM Gang
0
 
bczingoAuthor Commented:
Yes - the detail format - Moved all code from Load to Format Event - Preview still works fine but - Alas! No Joy! still no PDF data being filled
Thanks for suggestion though!
b
0
 
omgangCommented:
I am not yet using Access 2007 but it sounds as if the OutputTo action is not triggering any of the report event procedures.  In Access 2k & 2k3 I've output reports to PDF by changing the current printer to the PDF writer and then simply opening the report in normal view (i.e. Print) but that utilizes the OpenReport action not the OutputTo action.

OM Gang
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
omgangCommented:
The first link describes something similar and indicates there is something 'funny' about the OutputTo action for reports.  The second link also describes something similar with the suggestion to use Lebans method to create PDF docs.

OM Gang

http://g.www.ms.akadns.net/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.access.reports&tid=7cf7392f-9ab5-46b9-80ea-fbfd7f78f3af&cat=&lang=&cr=&sloc=&p=1

http://en.allexperts.com/q/Using-MS-Access-1440/2008/6/Output-PDF.htm
0
 
bczingoAuthor Commented:
Not all users have adobe PDF installed as a printer- should have to use this

I've seen several links to the Lebans method- It requires an addin which I can't use - Access 2007 should require this anyway
 
Its got to be possible to do (see last line of my question)

Thanks for researching though!
b
0
 
bczingoAuthor Commented:
should have to use this =should NOT have to use this
0
 
omgangCommented:
OK, I don't have any ideas right now but perhaps some testing will shed some light.  Have you tried displaying the report in Print Preview (which functions correctly) and then executing your OutputTo code while the Preview is displayed on screen?  Just curious if the OutputTo will use the loaded report or not.

Also, you are populating some text boxes at runtime with your report event procedures.  Is it possible to generate this data in the underlying query to avoid the need for the report event?

OM Gang
0
 
bczingoAuthor Commented:
happy New Year
I'll try the output while print preview is open-
The way the report is set up - the data is used in a format ( a lot of other apps use this same generated data - That I'm unable to bind the data - It needs to be populated at runtime
0
 
omgangCommented:
Just a thought for a possible workaround:  perhaps setting the text box ControlSource to a public function call.  Write public functions to generate/acquire the data to populate the text boxes.  I'm thinking you can accomplish the same result without using the report event procedures.

OM Gang
0
 
bczingoAuthor Commented:
I'll try - but I don't think the control source for anything gets called - good idea - I'll let you know
thanks!
b
0
 
bczingoAuthor Commented:
BTW - the previous print preview open idea makes no diff
0
 
bczingoAuthor Commented:
No - no function attached to source code gets called
just tried Save As PDF and it works fine too - theres got to be away for  OutputTo to have this same functionality
0
 
omgangCommented:
How much of a pain will it be for you to import the necessary db objects into a new Access db and post up here?  I am curious, as you are, and don't like the idea that it can't be done.  I'd like to take a look at the report, query, code etc. just so we can get two sets of eyes on it.

OM Gang
0
 
bczingoAuthor Commented:
damn - this seems impossible - but now it works - It seems thet you have to run the "OutputTo the PDF" immediately after preview report in code -
I can't believe I didn't do this at first but most of the time i was testing by running the line in immediate(debug) window -
Still don't know why the ribbon save as and export to work fine but definately the code needs to run after the preview opens without intereuption..
Oh well- I got it to work!
Thanks for your help!
I'm awarding points to you for keeping me on track
Thanks again
0
 
omgangCommented:
Now that is interesting.  When I suggested that you first preview the report and then issue the OutputTo command I actually wasn't thinking about inserting a
DoCmd.OpenReport "reportName", acViewPreview, etc.
immediately prior to the OutputTo command.  I was curious as to whether the OutputTo would utilize a loaded report and so resolve the problem and it appears that is does as long as the loaded report  is called from the procedure (as opposed to you opening it manually and then calling the procedure).

Good effort on your part for not giving up and figuring this out.  I can only imagine that this PAQ will benefit others.
OM Gang
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now