UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Outputto Does Not Execute Report_load, Access 2016    
 
   
whatacutup
post Jul 15 2019, 02:55 PM
Post#1



Posts: 217
Joined: 25-May 05



Hi all,

I am trying to use the OutputTo method to create a PDF of a report. The report has code which will run during the Report_Load event if I open the report on screen. When I send the report to a PDF file, it skips the Report_Load routine completely. I know this because the breakpoints I set never stopped the code execution. Any thoughts?

Thanks,
-Steph
Go to the top of the page
 
theDBguy
post Jul 15 2019, 02:58 PM
Post#2


Access Wiki and Forums Moderator
Posts: 76,000
Joined: 19-June 07
From: SunnySandyEggo


Can we see the code? It might help figure out what's happening.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
whatacutup
post Jul 15 2019, 03:13 PM
Post#3



Posts: 217
Joined: 25-May 05



Sure:

Function OutputReport(ObjectName As String, FileRoot As String, CustomerName As String, Optional Silent As Boolean) As String
Dim FilePath As String, FileName As String, ReportingYear As String, MinYear As String, MaxYear As String, YearText As String

On Error GoTo ErrHandler
FilePath = GetBEPath & "Invoices and Contracts\"
MkDir FilePath & CustomerName
FilePath = FilePath & CustomerName & "\"
FileRoot = Replace(FileRoot, "/", "")
FileRoot = Replace(FileRoot, ":", "")
FileRoot = Replace(FileRoot, "\", "")
FileRoot = Replace(FileRoot, "?", "")
FileName = FilePath & FileRoot & ".pdf"
DoCmd.OutputTo acOutputReport, ObjectName, acFormatPDF, FileName
If Silent <> True Then ShellExec """" & FileName & """"
OutputReport = FileName
Exit Function
ErrHandler:
If Err.Number = ERROR_FILE_PATH_ERROR Then Resume Next
MsgBox Err.Number & " " & Err.Description
End Function


This code has worked on plenty of other databases. I don't know why the Report_Load routine is not fired.
Go to the top of the page
 
whatacutup
post Jul 15 2019, 05:29 PM
Post#4



Posts: 217
Joined: 25-May 05



I should clarify that I have used this code on other projects but I don't recall if the reports being PDFed had code in them. In this case, the code adjusts column positions and visibility based on data found. The code runs fine when opening the report file but doesn't run at all when the report is output via the OutputTo method.
Go to the top of the page
 
whatacutup
post Jul 15 2019, 05:39 PM
Post#5



Posts: 217
Joined: 25-May 05



Okay I found the problem. Apparently, VBA does not fire the report code when using DoCmd.OutputTo. I found the answer here: http://www.UtterAccess.com/forum/Pdf-Print...p-t1977541.html

I modifed the code as follows:

.
.
.
DoCmd.OpenReport ObjectName, acViewPreview
DoCmd.OutputTo acOutputReport, "", acFormatPDF, FileName
If Silent <> True Then ShellExec """" & FileName & """"
OutputReport = FileName
DoCmd.Close acReport, ObjectName
.
.
.

And it works!

Go to the top of the page
 
theDBguy
post Jul 15 2019, 06:26 PM
Post#6


Access Wiki and Forums Moderator
Posts: 76,000
Joined: 19-June 07
From: SunnySandyEggo


Hi. Glad to hear you got it sorted out. Good luck with your project.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
whatacutup
post Jul 16 2019, 09:18 AM
Post#7



Posts: 217
Joined: 25-May 05



Thanks! It's apparently a longstanding issue in Access going way back.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    17th August 2019 - 08:11 PM