"Then, a Process button will be click in order to preview the report in a pdf format. "
Even if it's an old post (Nov 25 '08) and because it appears on google search and has no best answer yet, I have another possible answer:
1). In your OS (windows) install a virtual PDF printer (I use PDFCreator)
2). Make sure that the PDF Printer is set to display the .pdf file ! (in PDFCreator, set the options to automatically save the .pdf file into a specific folder - it could be temp folder - and then check that checkbox to open the saved .pdf file).
3). In Access, duplicate that report (let's say "Kreport" duplicated with the name "KreportPDF")
4). In Access on that duplicated report (KreportPDF) set as a specific printer that PDF printer: "Page Setup" -> "Page" -> "Printer for KreportPDF" -> "Use specific printer" -> "PDFCreator" (in my case)
5). In Access on that Kform make a button (ProcessButton) with the on click's properties to print the "KreportPDF".
PS: I dont know why, but on this case (PDF creator), the program (PDFCreator.exe) must be started to "print/save" the .pdf file. So I added this command to open the PDFCreator.exe minimized (tray zone):
Call shell("C:\Program Files\PDFCreator\PDFCreator.exe, vbMinimizedNoFocus) after the print report command. The button code looks like this:
- Private Sub ProcessButton_Click()
-
On Error GoTo Err_ProcessButton_Click
-
Dim StLinkCriteria As String
-
Dim StAppName As String
-
DoCmd.OpenReport "KreportPDF", acNormal, , StLinkCriteria
-
Call shell("C:\Program Files\PDFCreator\PDFCreator.exe, vbMinimizedNoFocus)
-
Exit_ProcessButton_Click:
-
Exit Sub
-
Err_ProcessButton_Click:
-
MsgBox Err.Description
-
Resume Exit_ProcessButton_Click
-
End Sub