473,326 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

I cannot install any pdf writers on the machine. I need to print a MS access 2000 report to a pdf file so I can email this. I already have a PDF995 printer in my windows list of printers. All this needs to be done by VBA code.
Apr 16 '07 #1
5 8030
pks00
280 Expert 100+
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. Declare Function GetPrivateProfileString Lib "kernel32" Alias _
  2.    "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
  3.    ByVal lpKeyName As Any, ByVal lpDefault As String, _
  4.    ByVal lpReturnedString As String, ByVal nSize As Long, _
  5.    ByVal lpFileName As String) As Long
  6.  
  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.  
  12. Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  13.  
  14. Sub pdfwrite(reportname As String, destpath As String, Optional strcriteria As String)
  15.  
  16.     Dim syncfile As String, maxwaittime As Long
  17.     Dim iniFileName As String, tmpPrinter As Printer
  18.     Dim outputfile As String, X As Long
  19.     Dim tmpoutputfile As String, tmpAutoLaunch As String
  20.  
  21. '***** IMPORTANT - SEE THIS *****
  22.     ' set the location of the PDF995.ini and the pdfsync files
  23.     iniFileName = "C:\Program Files\pdf995\res\pdf995.ini"
  24.     syncfile = "c:\documents and settings\all users\application data\pdf995\pdfsync.ini"
  25.  
  26.     If Mid(destpath, Len(destpath), 1) <> "\" Then destpath = destpath & "\"
  27.     outputfile = destpath & reportname & ".pdf"
  28.  
  29.     tmpoutputfile = ReadINIfile("PARAMETERS", "Output File", iniFileName)
  30.     tmpAutoLaunch = ReadINIfile("PARAMETERS", "Autolaunch", iniFileName)
  31.  
  32.     On Error Resume Next
  33.     Kill outputfile
  34.     On Error GoTo Cleanup
  35.  
  36.     X = WritePrivateProfileString("PARAMETERS", "Output File", outputfile, iniFileName)
  37.     X = WritePrivateProfileString("PARAMETERS", "AutoLaunch", "0", iniFileName)
  38.  
  39.     Set tmpPrinter = Application.Printer
  40.     Application.Printer = Application.Printers("PDF995")
  41.  
  42.     DoCmd.OpenReport reportname, acViewNormal, , strcriteria
  43.  
  44.     Sleep (10000)
  45.     maxwaittime = 300000 'If pdf995 isn't done in 5 min, quit anyway
  46.     Do While ReadINIfile("PARAMETERS", "Generating PDF CS", syncfile) = "1" And maxwaittime > 0
  47.         Sleep (10000)
  48.         maxwaittime = maxwaittime - 10000
  49.     Loop
  50.  
  51. Cleanup:
  52.     Sleep (10000)
  53.     X = WritePrivateProfileString("PARAMETERS", "Output File", tmpoutputfile, iniFileName)
  54.     X = WritePrivateProfileString("PARAMETERS", "AutoLaunch", tmpAutoLaunch, iniFileName)
  55.     X = WritePrivateProfileString("PARAMETERS", "Launch", "", iniFileName)
  56.     On Error Resume Next
  57.  
  58.     Application.Printer = tmpPrinter
  59.  
  60. End Sub
  61.  
  62. Function ReadINIfile(sSection As String, sEntry As String, sFileName As String) As String
  63.  
  64.     Dim X As Long
  65.     Dim sDefault As String
  66.     Dim sRetBuf As String, iLenBuf As Integer
  67.     Dim sValue As String
  68.  
  69.     sDefault$ = ""
  70.     sRetBuf$ = String$(256, 0)   '256 null characters
  71.     iLenBuf% = Len(sRetBuf$)
  72.     X = GetPrivateProfileString(sSection, sEntry, _
  73.                sDefault$, sRetBuf$, iLenBuf%, sFileName)
  74.     ReadINIfile = Left$(sRetBuf$, X)
  75.  
  76. End Function
  77.  
Apr 16 '07 #2
Hi,
Thanks for the speedy reply.

I tried the code but did not work. I did not get any errors though.
Firstly, I cannot find the file
syncfile = "c:\documents and settings\all users\application data\pdf995\pdfsync.ini"
I searched for it in my entire C: drive. I do not have any other drives.

Secondly, I had to comment the following code as it is not supported by MS Access 2000;
'tmpPrinter As Printer
'Set tmpPrinter = Application.Printer
'Application.Printer = Application.Printers("PDF995")
'Application.Printer = tmpPrinter
Apr 16 '07 #3
Hi,

This code that you gave me was not working. I tried it again today, and for some reason, it works superbly without any errors. I am not sure why, maybe I needed to reboot my machine or something...Anyways, thanks...
Apr 18 '07 #4
pks00
280 Expert 100+
Glad its working.
Ive tested this code and it works sweet for me. It now appears its working for you. Not sure why it didnt work in the first place, I can only imagine it wasnt working due to some configuration issue.
Apr 18 '07 #5
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. Declare Function GetPrivateProfileString Lib "kernel32" Alias _
  2.    "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
  3.    ByVal lpKeyName As Any, ByVal lpDefault As String, _
  4.    ByVal lpReturnedString As String, ByVal nSize As Long, _
  5.    ByVal lpFileName As String) As Long
  6.  
  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.  
  12. Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  13.  
  14. Sub pdfwrite(reportname As String, destpath As String, Optional strcriteria As String)
  15.  
  16.     Dim syncfile As String, maxwaittime As Long
  17.     Dim iniFileName As String, tmpPrinter As Printer
  18.     Dim outputfile As String, X As Long
  19.     Dim tmpoutputfile As String, tmpAutoLaunch As String
  20.  
  21. '***** IMPORTANT - SEE THIS *****
  22.     ' set the location of the PDF995.ini and the pdfsync files
  23.     iniFileName = "C:\Program Files\pdf995\res\pdf995.ini"
  24.     syncfile = "c:\documents and settings\all users\application data\pdf995\pdfsync.ini"
  25.  
  26.     If Mid(destpath, Len(destpath), 1) <> "\" Then destpath = destpath & "\"
  27.     outputfile = destpath & reportname & ".pdf"
  28.  
  29.     tmpoutputfile = ReadINIfile("PARAMETERS", "Output File", iniFileName)
  30.     tmpAutoLaunch = ReadINIfile("PARAMETERS", "Autolaunch", iniFileName)
  31.  
  32.     On Error Resume Next
  33.     Kill outputfile
  34.     On Error GoTo Cleanup
  35.  
  36.     X = WritePrivateProfileString("PARAMETERS", "Output File", outputfile, iniFileName)
  37.     X = WritePrivateProfileString("PARAMETERS", "AutoLaunch", "0", iniFileName)
  38.  
  39.     Set tmpPrinter = Application.Printer
  40.     Application.Printer = Application.Printers("PDF995")
  41.  
  42.     DoCmd.OpenReport reportname, acViewNormal, , strcriteria
  43.  
  44.     Sleep (10000)
  45.     maxwaittime = 300000 'If pdf995 isn't done in 5 min, quit anyway
  46.     Do While ReadINIfile("PARAMETERS", "Generating PDF CS", syncfile) = "1" And maxwaittime > 0
  47.         Sleep (10000)
  48.         maxwaittime = maxwaittime - 10000
  49.     Loop
  50.  
  51. Cleanup:
  52.     Sleep (10000)
  53.     X = WritePrivateProfileString("PARAMETERS", "Output File", tmpoutputfile, iniFileName)
  54.     X = WritePrivateProfileString("PARAMETERS", "AutoLaunch", tmpAutoLaunch, iniFileName)
  55.     X = WritePrivateProfileString("PARAMETERS", "Launch", "", iniFileName)
  56.     On Error Resume Next
  57.  
  58.     Application.Printer = tmpPrinter
  59.  
  60. End Sub
  61.  
  62. Function ReadINIfile(sSection As String, sEntry As String, sFileName As String) As String
  63.  
  64.     Dim X As Long
  65.     Dim sDefault As String
  66.     Dim sRetBuf As String, iLenBuf As Integer
  67.     Dim sValue As String
  68.  
  69.     sDefault$ = ""
  70.     sRetBuf$ = String$(256, 0)   '256 null characters
  71.     iLenBuf% = Len(sRetBuf$)
  72.     X = GetPrivateProfileString(sSection, sEntry, _
  73.                sDefault$, sRetBuf$, iLenBuf%, sFileName)
  74.     ReadINIfile = Left$(sRetBuf$, X)
  75.  
  76. End Function
  77.  
HI pks00

I was going through the codes as i have a similar problem. I want to generate the report in PDF format when a command button is clicked

But as i am new to the access programming. I could not understand it properly.

Could you please help me out as to How to generate a report in PDF format when a command button is clicked. I too Have "PDF995" as well as "Cute PDF writer"

Please help me out.
Thank you

Regards
Manoj
Sep 21 '07 #6

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

Similar topics

3
by: gudia | last post by:
I want to Programatically generate Access reports in the pdf format using some tool and then email them to people in the same code. Right now I am trying to do this with pdf995 using VBA (emailing...
16
by: cyranoVR | last post by:
This is the approach I used to automate printing of Microsoft Access reports to PDF format i.e. unattended and without annoying "Save As..." dialogs, and - more importantly - without having to use...
9
by: cantelow | last post by:
Hi. I've got a program printing multiple pdf reports, and I need to wait for completion of various associated operations- The pdf printer prints to one file, then I need to copy that where I need...
1
by: Jason | last post by:
For some reason, most but not all reports printing from an access application our client is using will not print any images on the reports or forms. One report will print the image and data...
1
by: Thomas Zimmermann | last post by:
Is it possible from VBA to control which printer a report is send to? The "DoCmd.OpenReport", always sends the job to the standardprinter, but I want to be able to specify an alternative printer...
13
by: salad | last post by:
Hi Guys: I was stuck. I needed to send a report to a file. My beautiful report(s) in Access were going to require loss of formatting with RTFs, a PITA in WordMailMerge, sending it as a text...
8
by: jbonifacejr | last post by:
This is my first day here, so please be patient. I do not know how to search very well so the search I tried to get the answer showed me topics from the year 2000 and they really don't cover what I...
1
by: Gilberto | last post by:
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...
10
by: Snoopy33 | last post by:
I have a DB that I developed on access XP (2002) and deployed over a year ago. No one has had problems printing any of the reports within the DB until we started loading 2007 on new computers. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.