Filter a function that runs a report as a pdf (RunReportAsPDF)

A

Amp

Is it possible to filter a function that runs a report as a pdf
(RunReportAsPDF)?

the relevant code is below:

Public Function RunReportAsPDF(prmRptName As String, _
prmPdfName As String) As Boolean

' Returns TRUE if a PDF file has been created

Dim AdobeDevice As String
Dim strDefaultPrinter As String

'Find the Acrobat PDF device

AdobeDevice = GetRegistryValue(HKEY_CURRENT_USER, _
"Software\Microsoft\WIndows
NT\CurrentVersion\Devices", _
"Adobe PDF")

If AdobeDevice = "" Then ' The device was not found
MsgBox "You must install Acrobat Writer before using this feature"
RunReportAsPDF = False
Exit Function
End If

' get current default printer.
strDefaultPrinter = Application.Printer.DeviceName

Set Application.Printer = Application.Printers("Adobe PDF")

'Create the Registry Key where Acrobat looks for a file name
CreateNewRegistryKey HKEY_CURRENT_USER, _
"Software\Adobe\Acrobat Distiller\PrinterJobControl"

'Put the output filename where Acrobat could find it
SetRegistryValue HKEY_CURRENT_USER, _
"Software\Adobe\Acrobat Distiller\PrinterJobControl", _
Find_Exe_Name(CurrentDb.Name, CurrentDb.Name), _
prmPdfName

On Error GoTo Err_handler

DoCmd.OpenReport "ORDERS REPORT",

While Len(Dir(prmPdfName)) = 0 ' Wait for the PDF to actually
exist
DoEvents
Wend

RunReportAsPDF = True ' Mission accomplished!

Normal_Exit:

Set Application.Printer = Application.Printers(strDefaultPrinter) '
Restore default printer

On Error GoTo 0

Exit Function

Err_handler:

If Err.Number = 2501 Then ' The report did not run properly (ex NO DATA)
RunReportAsPDF = False
Resume Normal_Exit
Else
RunReportAsPDF = False ' The report did not run properly (anything
else!)
MsgBox "Unexpected error #" & Err.Number & " - " & Err.Description
Resume Normal_Exit
End If

End Function

I am calling the function from another module. If possible I want to
synchronzie the pointer of the current ADO connection with a filter to the
RunReportAsPDF function. I have attempted to played around with the
recordset.clone but it wasn't successful. If the filtername or openargs
moptional arguments are used then its seems like I would have to pass a
argument through the filter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top