How do I name files when batch printing to a PDF writer?

  • Thread starter Thread starter M Skabialka
  • Start date Start date
M

M Skabialka

My initial challenge was to find a way to put complex Access 2000 reports at
a location acsessible to a web site.
All of the Export to HTML, Export to Word, Excel, Snapshot features
seriously distorted the report which has very exacting requirements. Using
other code gleaned from experts on this site I learned to output to .emf
files but therse can't be viewed directly without being inserted into
something like PowerPoint, Word, etc.

Then it was suggested I use a PDF format, and using code written by Albert
D. Kallal was able to change the printer to the PDF converter as needed,
using the PDF995 PDF product, so solved half my problem.
http://www.attcanada.net/~kallal.msn/msaccess/msaccess.html

Here's the code I used using Albert's sample database:

' Thus, when printing a report, you can:
' 1) save the default printer into a string
strCurrentPtr = GetDefaultPrinter
' 2) switch to your report printer
strReportsPtr = "PDF995"
SetDefaultPrinter strReportsPtr
' 3) print report
DocName = "rptAcctSummary"
DoCmd.OpenReport DocName, acViewNormal '(There will be
criteria here)
' 4) switch back to the default printer
SetDefaultPrinter strCurrentPtr

Here's the other half of my problem:
I want to run the report about 150 times, each time using a different
account number, so each of the reports has to be named the account number;
eg 400034.pdf.
Since the actual report name in Access 2000 is rptAcctSummary, and PDF995
can either sequentially number the reports (1.pdf, 2.pdf) or call it
rptAcctSummary.pdf, or ask for a name and location every time it is run, how
can I make a batch run that will name these reports by the account number?
I will be using a loop based on a query of all active account numbers to run
each report.

So I need 100365.pdf, 114234.pdf, 400564.pdf, etc

Is there any more great wisdom out there which will help me complete my
project?
Thanks to all so far
Mich
 
You could pay the $99.95 and build your solution a number of ways
in a few minutes using one of our products. You need to decide whether
yuu want to push reports in a batch mode to your web site or have users
generate reports "live". I do agree that PDF is the best format to use.

If you want to spend hours of your time so you can go the "free" method
look into passing in either a where clause or changing the queries driving
the reports
before the report is run. You could even steal some code from our examples
and
try and duplicate some of the functionality of what our products do.

HTH,
Mark
RPT Software
http://www.rptsoftware.com
 
how can I make a batch run that will name these reports by the account
number?

PDF995 uses pdf995.ini file for its settings it's located in ..\pdf995\res\
You need to set the "Output File" parameter to your file name for example
Output File=C:\Temp\PDF995.pdf here is a sample.

Careful with the line wraps
' ------------------ END CODE -----------------
Const PDF995 = "C:\pdf995\res\pdf995.ini"

Private Declare Function GetPrivateProfileString Lib "kernel32.dll" Alias
"GetPrivateProfileStringA" (ByVal lpSection As String, ByVal lpSetting As
String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal
nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function SetPrivateProfileString Lib "kernel32.dll" Alias
"WritePrivateProfileStringA" (ByVal lpSection As String, ByVal lpSetting As
String, ByVal lpValue As String, ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileSectionNames Lib "kernel32.dll"
Alias "GetPrivateProfileSectionNamesA" (ByVal lpszReturnBuffer As String,
ByVal nSize As Long, ByVal lpFileName As String) As Long

Public Function GetIniSetting(ByRef iniFilename As String, ByRef Section As
String, ByRef Setting As String) As String
On Error GoTo Proc_Error
Dim Count As Long
Dim ReturnedString As String
ReturnedString = String(256, 0)

Count = GetPrivateProfileString(Section, Setting, "", ReturnedString,
255, iniFilename)
GetIniSetting = Left$(ReturnedString, Count)
Proc_Exit:
Exit Function
Proc_Error:
MsgBox Err.Description
Resume Proc_Exit
End Function

Public Sub SetIniSetting(ByRef iniFilename As String, ByRef Section As
String, ByRef Setting As String, ByRef Value As String)
On Error GoTo Proc_Error
SetPrivateProfileString Section, Setting, Value, iniFilename

Proc_Exit:
Exit Sub
Proc_Error:
MsgBox Err.Description
Resume Proc_Exit
End Sub

Sub Test_PDF995()
Dim strOutPutFile As String 'Stores current Output File setting
Dim strPDFFile As String

strPDFFile = "C:\Temp\PDF995.pdf"

'Save Output File setting
strOutPutFile = GetIniSetting(PDF995, "Parameters", "Output File")
'Set PDF File Name
SetIniSetting PDF995, "Parameters", "Output File", strPDFFile
'Print Report

'Restore Output File setting
SetIniSetting PDF995, "Parameters", "Output File", strOutPutFile
End Sub
' ------------------ END CODE -----------------

Call SetIniSetting prior to printing each report to bypass the Save As
dialog, Setting Output File= will display the SaveAs dialog.

That's my $0.00 solution.

HTH

Jose
 
Jose,
Thanks for the code but I can't figure out how to use it...
I've tried putting your code all sorts of places slipped into my code but am
confused as to what your code is doing so don't know how to apply it to
mine!

Would you mind helping me a little more here?
eg: What do "Parameters", "Output File", strPDFFile and strOutPutFile
represent?

strOutPutFile = GetIniSetting(PDF995, "Parameters", "Output File")
'Set PDF File Name
SetIniSetting PDF995, "Parameters", "Output File", strPDFFile
'Print Report
'Restore Output File setting
SetIniSetting PDF995, "Parameters", "Output File", strOutPutFile

How can I use that in my code (below)?


' 1) save the default printer into a string
strCurrentPtr = GetDefaultPrinter
' 2) switch to your report printer
strReportsPtr = "PDF995"
SetDefaultPrinter strReportsPtr
' 3) print report - Actually loop through all accts, printing one
report per account
DocName = "rptAcctSummary"
DoCmd.OpenReport DocName, acViewNormal '(There will be
'criteria here which includes the acct # I am dealing with, therefore
knowing
'the name of the report when saved, eg: 100342.pdf)

' 4) switch back to the default printer
SetDefaultPrinter strCurrentPtr

Thanks,
Mich
 
PDF995 saves its settings in C:\pdf995\res\pdf995.ini You can view this file
in Notepad
What do "Parameters", "Output File", strPDFFile and strOutPutFile
represent?

Parameters is the section in you want to change.
Output File is the setting within [Parameters] section you want to change.
This is the PDF file Name.
PDF995 is a constant set to the location of PDF995.ini
(C:\pdf995\res\pdf995.ini)
strOutPutFile stores the old value in "Output File" setting
strPDFFile should be the path to your PDF file name for example
C:\Temp\100342.pdf

Your code should look something like this

save the default printer into a string strCurrentPtr = GetDefaultPrinter
switch to your report printer
strReportsPtr = "PDF995"
SetDefaultPrinter strReportsPtr

DocName = "rptAcctSummary"

' Save PDF995 "Output File" Setting
strOutPutFile = GetIniSetting(PDF995, "Parameters", "Output File")
'print report - Actually loop through all accts, printing one report per
account
Do Until oRst.EOF
strPDFFile = "C:\Temp\" & oRst![ACCT#] & ".pdf"

SetIniSetting PDF995, "Parameters", "Output File", strPDFFile
'(There will be criteria here which includes the acct # I am
'dealing with, therefore knowing the name of the report
'when saved, eg: 100342.pdf)
DoCmd.OpenReport DocName, acViewNormal
oRst.MoveNext
Loop

'Restore PDF995 "Output File" setting
SetIniSetting PDF995, "Parameters", "Output File", strOutPutFile

switch back to the default printer
SetDefaultPrinter strCurrentPtr



HTH

Jose
 
I finally got the code working as you showed me here and proudly showed off
how this will work with multiple .pdf files based on the account number...
BUT...

They told me that PDF995 isn't what they want to use; they have Adobe
Acrobat on all machines, so want to use the "Adobe PDFWriter" instead of
"PDF995"

So now I am back to square one.

Do you by any chance know how to change the output file name when using
Adobe PDFWriter instead of PDF995?

Thanks for all your help so far
Mich


Jose Hernandez said:
PDF995 saves its settings in C:\pdf995\res\pdf995.ini You can view this file
in Notepad
What do "Parameters", "Output File", strPDFFile and strOutPutFile
represent?

Parameters is the section in you want to change.
Output File is the setting within [Parameters] section you want to change.
This is the PDF file Name.
PDF995 is a constant set to the location of PDF995.ini
(C:\pdf995\res\pdf995.ini)
strOutPutFile stores the old value in "Output File" setting
strPDFFile should be the path to your PDF file name for example
C:\Temp\100342.pdf

Your code should look something like this

save the default printer into a string strCurrentPtr = GetDefaultPrinter
switch to your report printer
strReportsPtr = "PDF995"
SetDefaultPrinter strReportsPtr

DocName = "rptAcctSummary"

' Save PDF995 "Output File" Setting
strOutPutFile = GetIniSetting(PDF995, "Parameters", "Output File")
'print report - Actually loop through all accts, printing one report per
account
Do Until oRst.EOF
strPDFFile = "C:\Temp\" & oRst![ACCT#] & ".pdf"

SetIniSetting PDF995, "Parameters", "Output File", strPDFFile
'(There will be criteria here which includes the acct # I am
'dealing with, therefore knowing the name of the report
'when saved, eg: 100342.pdf)
DoCmd.OpenReport DocName, acViewNormal
oRst.MoveNext
Loop

'Restore PDF995 "Output File" setting
SetIniSetting PDF995, "Parameters", "Output File", strOutPutFile

switch back to the default printer
SetDefaultPrinter strCurrentPtr



HTH

Jose


M Skabialka said:
Jose,
Thanks for the code but I can't figure out how to use it...
I've tried putting your code all sorts of places slipped into my code
but
am
confused as to what your code is doing so don't know how to apply it to
mine!

Would you mind helping me a little more here?
eg: What do "Parameters", "Output File", strPDFFile and strOutPutFile
represent?

strOutPutFile = GetIniSetting(PDF995, "Parameters", "Output File")
'Set PDF File Name
SetIniSetting PDF995, "Parameters", "Output File", strPDFFile
'Print Report
'Restore Output File setting
SetIniSetting PDF995, "Parameters", "Output File", strOutPutFile

How can I use that in my code (below)?


' 1) save the default printer into a string
strCurrentPtr = GetDefaultPrinter
' 2) switch to your report printer
strReportsPtr = "PDF995"
SetDefaultPrinter strReportsPtr
' 3) print report - Actually loop through all accts, printing one
report per account
DocName = "rptAcctSummary"
DoCmd.OpenReport DocName, acViewNormal '(There will be
'criteria here which includes the acct # I am dealing with, therefore
knowing
'the name of the report when saved, eg: 100342.pdf)

' 4) switch back to the default printer
SetDefaultPrinter strCurrentPtr

Thanks,
Mich
 
I also had the same issue. However following the instructions posted
here in the $0.00 method. I have PDF files but the file size is 0Kb.
Of course, Acrobat reader has a problem when opening the file. any
suggestions to what I may have done wrong?
 
Back
Top