By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,389 Members | 2,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,389 IT Pros & Developers. It's quick & easy.

RE: How to print MS Access 2000 report to PDF995 printer by VBA Code

100+
P: 135
pks00
Expert
280 Posts April 16th, 2007
01:08 PM

Re: How to print MS Access 2000 report to PDF995 printer by VBA Code

Sweet, your using pdf995, makes answering this question that much easier :)


okay, here is some vba code. Ive got a function called pdfwrite which you call passing in the name of the report, pdf destination and any criteria for running the report. Add this lot to a module

Look for comments saying "IMPORTANT
u need to change the paths to reflect your installation

Expand|Select|Wrap|Line Numbers
  1.  
  2. Declare Function GetPrivateProfileString Lib "kernel32" Alias _ 
  3. "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _ 
  4. ByVal lpKeyName As Any, ByVal lpDefault As String, _ 
  5. ByVal lpReturnedString As String, ByVal nSize As Long, _ 
  6. ByVal lpFileName As String) As Long 
  7. Declare Function WritePrivateProfileString Lib "kernel32" Alias _ 
  8. "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _ 
  9. ByVal lpKeyName As Any, ByVal lpString As Any, _ 
  10. ByVal lpFileName As String) As Long 
  11. Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 
  12. Sub pdfwrite(reportname As String, destpath As String, Optional strcriteria As String) 
  13. Dim syncfile As String, maxwaittime As Long 
  14. Dim iniFileName As String, tmpPrinter As Printer 
  15. Dim outputfile As String, X As Long 
  16. Dim tmpoutputfile As String, tmpAutoLaunch As String 
  17. '***** IMPORTANT - SEE THIS ***** 
  18. ' set the location of the PDF995.ini and the pdfsync files 
  19. iniFileName = "C:\Program Files\pdf995\res\pdf995.ini" 
  20. syncfile = "c:\documents and settings\all users\application data\pdf995\pdfsync.ini" 
  21. If Mid(destpath, Len(destpath), 1) <> "\" Then destpath = destpath & "\" 
  22. outputfile = destpath & reportname & ".pdf" 
  23. tmpoutputfile = ReadINIfile("PARAMETERS", "Output File", iniFileName) 
  24. tmpAutoLaunch = ReadINIfile("PARAMETERS", "Autolaunch", iniFileName) 
  25. On Error Resume Next 
  26. Kill outputfile 
  27. On Error GoTo Cleanup 
  28. X = WritePrivateProfileString("PARAMETERS", "Output File", outputfile, iniFileName) 
  29. X = WritePrivateProfileString("PARAMETERS", "AutoLaunch", "0", iniFileName) 
  30. Set tmpPrinter = Application.Printer 
  31. Application.Printer = Application.Printers("PDF995") 
  32. DoCmd.OpenReport reportname, acViewNormal, , strcriteria 
  33. Sleep (10000) 
  34. maxwaittime = 300000 'If pdf995 isn't done in 5 min, quit anyway 
  35. Do While ReadINIfile("PARAMETERS", "Generating PDF CS", syncfile) = "1" And maxwaittime > 0 
  36. Sleep (10000) 
  37. maxwaittime = maxwaittime - 10000 
  38. Loop 
  39. Cleanup: 
  40. Sleep (10000) 
  41. X = WritePrivateProfileString("PARAMETERS", "Output File", tmpoutputfile, iniFileName) 
  42. X = WritePrivateProfileString("PARAMETERS", "AutoLaunch", tmpAutoLaunch, iniFileName) 
  43. X = WritePrivateProfileString("PARAMETERS", "Launch", "", iniFileName) 
  44. On Error Resume Next 
  45. Application.Printer = tmpPrinter 
  46. End Sub 
  47. Function ReadINIfile(sSection As String, sEntry As String, sFileName As String) As String 
  48. Dim X As Long 
  49. Dim sDefault As String 
  50. Dim sRetBuf As String, iLenBuf As Integer 
  51. Dim sValue As String 
  52. sDefault$ = "" 
  53. sRetBuf$ = String$(256, 0) '256 null characters 
  54. iLenBuf% = Len(sRetBuf$) 
  55. X = GetPrivateProfileString(sSection, sEntry, _ 
  56. sDefault$, sRetBuf$, iLenBuf%, sFileName) 
  57. ReadINIfile = Left$(sRetBuf$, X) 
  58. End Function
  59.  


Following this old thread i was just wondering WHERE exactly i should enter the code??? Sorry but im new on this.

Thanks,
Gilberto
Oct 9 '07 #1
Share this Question
Share on Google+
1 Reply


nico5038
Expert 2.5K+
P: 3,072
Just create a new module and name it e.g. "modPrintPDF".
Copy/paste the code and give it a try.

Nic;o)
Oct 9 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.