Access to PDF995 filename

  • Thread starter Thread starter OceansideDJ
  • Start date Start date
O

OceansideDJ

I used the report caption to create the filename that PDF Writer would default
to. Now I am using PDF995. Can the output filename be controlled beyond the
choices in PDFEdit995?

Thanks,

Mike
 
Mike:

Our PDF and Mail Library allows you to automate the output of PDF files
using PDF 995 and set what ever file name you want to at run time. Take a
look in the developer tools area of our web.
 
PDFEdit995 is just an interface to ...\pdf995\res\pdf995.ini you can open it
in notepad and change the settings mannually.

Here is a sample module that changes the Output File Name in pdf995.ini for
each report printed.

Carefule with line wraps.
'------------------ CODE START -----------------------------------
Option Compare Database
Option Explicit

'AUTHOR: Jose Hernandez
'PDF995 Developer's FAQ: http://www.pdf995.com/faq_dev.html
Private Const PDF995_RES = "C:\pdf995\res"
Private Const PDF995 = PDF995_RES & "\pdf995.ini"
Private Const PDFSYNC = PDF995_RES & "\pdfsync.ini"

'Any change to the last write-time of files in the watched directory or
'subtree causes a change notification wait operation to return.
'The operating system detects a change to the last write-time only when the
'file is written to the disk. For operating systems that use extensive
caching,
'detection occurs only when the cache is sufficiently flushed.
Private Const FILE_NOTIFY_CHANGE_LAST_WRITE = &H10

'If the function succeeds, the return value is a handle to a find change
notification object.
Private Declare Function FindFirstChangeNotification Lib "kernel32" Alias
"FindFirstChangeNotificationA" (ByVal lpPathName As String, ByVal
bWatchSubtree As Long, ByVal dwNotifyFilter As Long) As Long
'If the function succeeds, the return value is nonzero.
Private Declare Function FindNextChangeNotification Lib "kernel32" (ByVal
hChangeHandle As Long) As Long
Private Declare Function FindCloseChangeNotification Lib "kernel32" (ByVal
hChangeHandle As Long) As Long
'If the function succeeds, the return value indicates the event that caused
the function to return.
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle
As Long, ByVal dwMilliseconds As Long) As Long
'The state of the specified object signaled.
Private Const WAIT_OBJECT_0 As Long = &H0
'The specified object is a mutex object that was not released by the thread
that
'owned the mutex object before the owning thread terminated. Ownership of
the mutex
'object is granted to the calling thread, and the mutex is set to
nonsignaled.
Private Const WAIT_ABANDONED As Long = &H80
'The time-out interval elapsed, and the object's state is nonsignaled.
Private Const WAIT_TIMEOUT As Long = &H102
Private Const WAIT_FAILED = &HFFFFFFFF

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 Sub TestPDF995()
On Error GoTo Proc_Error
'REQUIRED: ADO reference.
Dim strOutPutFile As String
Dim rstCust As ADODB.Recordset
Dim strPDFFile As String
Dim strReport As String

strReport = "rptCustomers"
Set rstCust = New ADODB.Recordset
With rstCust
.Open "SELECT TOP 10 Country FROM qryCustmersByCountry;",
CurrentProject.Connection, adOpenDynamic, adLockOptimistic
End With

'Save Output File setting
strOutPutFile = GetIniSetting(PDF995, "Parameters", "Output File")

Do Until rstCust.EOF
strPDFFile = "C:\Temp\" & rstCust![Country] & ".pdf"
SetIniSetting PDF995, "Parameters", "Output File", strPDFFile
Debug.Print strPDFFile
DoCmd.OpenReport strReport, acViewNormal, , "[Country] = '" &
rstCust![Country] & "'"
Call WaitFor_PDF995
rstCust.MoveNext
Loop

Proc_Exit:
'Restore Output File setting
SetIniSetting PDF995, "Parameters", "Output File", strOutPutFile
Exit Sub
Proc_Error:
MsgBox Err.Description
Resume Proc_Exit
End Sub

Private Function GetIniSetting(ByRef iniFilename As String, ByRef Section As
String, ByRef Setting As String) As String
On Error GoTo Proc_Error
Dim lngRetVal As Long
Dim strBuffer As String
strBuffer = String(256, 0)

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

Private 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

Function WaitFor_PDF995() As Long
On Error GoTo Proc_Error
Dim lngRetVal As Long
Dim lngWaitVal As Long
Dim strGenerating_PDF_CS(1) As String
Dim bolExit As Boolean

bolExit = False
'Set the notification hook
lngRetVal = FindFirstChangeNotification(PDF995_RES, 0,
FILE_NOTIFY_CHANGE_LAST_WRITE)
Do
'Wait until the event is triggered, 60000 = 1 minute
lngWaitVal = WaitForSingleObject(lngRetVal, 10000)
If lngWaitVal = WAIT_FAILED Then
WaitFor_PDF995 = lngWaitVal
Exit Do
End If
strGenerating_PDF_CS(1) = strGenerating_PDF_CS(0)
'[Generating PDF CS] Values: 0 = Finished, 1 = Generating PDF
strGenerating_PDF_CS(0) = GetIniSetting(PDFSYNC, "Parameters",
"Generating PDF CS")
'Debug.Print lngWaitVal & " 0: " & strGenerating_PDF_CS(0) & " 1: "
& strGenerating_PDF_CS(1)
If strGenerating_PDF_CS(0) = "0" And strGenerating_PDF_CS(1) = "1"
Then Exit Do
If lngWaitVal = WAIT_TIMEOUT And strGenerating_PDF_CS(0) = "0" Then
WaitFor_PDF995 = lngWaitVal
Exit Do
End If
FindNextChangeNotification lngRetVal
Loop Until bolExit = True

Proc_Exit:
Erase strGenerating_PDF_CS
FindCloseChangeNotification lngRetVal
Exit Function
Proc_Error:
MsgBox Err.Description, vbCritical
Resume Proc_Exit
End Function

'------------------ CODE END -----------------------------------

HTH

Jose
 
Back
Top