[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1739
  • Last Modified:

Output to PDF using multiple reports.

I have the following code that works fine. The basics are i have a form with a combobox. I click a command button on the form that outputs currently in SNP format various reports based on the elements in the combobox. The reports are outputted with unique names from the combobox. In addition there is an extra bit of code at the bottom that opens up another report via the button and 'virtually' prints that.

Private Sub Command10_Click()
On Error GoTo Error_Routine
   
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim RS As DAO.Recordset
    Dim ctlComboBox As Control
    Dim RS2 As DAO.Recordset           ' new recordset to output separate report
    Dim qdf2 As DAO.QueryDef

' the underlying recordset for the report is a query
    Set db = CurrentDb()
    Set qdf = db.QueryDefs("qry_herb_exc_design&conagro")
        qdf.Parameters(0) = Forms!frm_shedno_herb!cmb_shedherb.Value
    Set RS = qdf.OpenRecordset()
    Set ctlComboBox = Forms!frm_shedno_herb!cmb_shedherb
   
  Dim i As Integer   'loop counter for items selected from combobox
                     'enumerate through each of the items in combo box
         
For i = 0 To ctlComboBox.ListCount - 1

    ctlComboBox = cmb_shedherb.ItemData(i)
    ctlComboBox.Requery
         
    'preview report to apply filter
    DoCmd.OpenReport "rpt_herb_exc_design&conagro_wklist", acViewPreview, , "Left([Funct# Location],6)='" & ctlComboBox.ItemData(i) & "'"
    DoCmd.OutputTo acOutputReport, "rpt_herb_exc_design&conagro_wklist", acFormatSNP, "P:\Planning Engineers\weeklytest\" & ctlComboBox.ItemData(i) & ".snp", False
    DoCmd.Close acReport, "rpt_herb_exc_design&conagro_wklist"
   
Next i

RS.Close
Set RS = Nothing
Set ctlComboBox = Nothing
i = 0
   
      Set qdf2 = db.QueryDefs("qry_plan_vs_res_herbs")   ' assumes no parameters coming from a combo box
    Set RS2 = qdf.OpenRecordset()
   
    DoCmd.OpenReport "rpt_plan_vs_res_herbs", acViewPreview   'output resource report via snapshot to web area
    DoCmd.OutputTo acOutputReport, "rpt_plan_vs_res_herbs", acFormatSNP, "P:\Planning Engineers\weeklytest\" & "10weekherb" & ".snp", False
   'close resource report
    DoCmd.Close acReport, "rpt_plan_vs_res_herbs"

RS2.Close                                                 'closing code for second recordset
Set RS2 = Nothing

Exit_Continue:
        Exit Sub
Error_Routine:
        MsgBox "Error# " & Err.Number & " " & Err.Description
        Resume Exit_Continue
       

End Sub  


Now i don't like the control features you get with SNP like fit to screen etc. i want to revert to PDF. Now i have found this code via a buried link on EE. I have copied everything including the notes at the top. I do have PDF995 installed on my computer. I use Access 2000
Code/wording as follows:-

VBA code that successfully converts an Access report to a PDF file.

Instructions:

Copy everything below the line into a module in an Access database.

To use the code on Access 2000 and earlier, it is necessary to comment out
three lines referring to the printer object and set the report to use PDF995
in the report page layout dialog.

The only way to change the printer for a report in these
previous versions is to open the report in design mode and make the change,
re-save the report, and then run it.



To create your pdf file, call the function  
pdfwrite "report name","report filter(may be "")","Path to put the
pdf"

A new pdf file named with the name of the report will be created.

------------------------------------------------------
Option Compare Database
Option Explicit

'Read INI settings
Declare Function GetPrivateProfileString Lib "kernel32" Alias _
   "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
   ByVal lpKeyName As Any, ByVal lpDefault As String, _
   ByVal lpReturnedString As String, ByVal nSize As Long, _
   ByVal lpFileName As String) As Long

'Write settings
Declare Function WritePrivateProfileString Lib "kernel32" Alias _
   "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
   ByVal lpKeyName As Any, ByVal lpString As Any, _
   ByVal lpFileName As String) As Long

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub pdfwrite(reportname As String, destpath As String, Optional strcriteria As String)

' Runs an Access report to PDF995 to create a pdf file from the report.
' Input parameters are the name of the report within the current database,
' the path for the output file, and an optional criteria for the report

' Be sure to check that the "Generating PDF CS" setting in pdfsync.ini is set to 0
' when pdf995 is idle. This codes uses that as a completion flag as it seems to be
' the most reliable indication that PDF995 is done writing the pdf file.


' Note: The application.printer object is not valid in Access 2000
' and earlier. In that case, set the printer in the report to pdf995
' and comment out the references herein to the application.printer

Dim syncfile As String, maxwaittime As Long
Dim iniFileName As String, tmpPrinter As Printer
Dim outputfile As String, x As Long
Dim tmpoutputfile As String, tmpAutoLaunch As String

' set the location of the PDF995.ini and the pdfsync files
iniFileName = "c:\pdf995\res\pdf995.ini"
syncfile = "c:\documents and settings\all users\application data\pdf995\res\pdfsync.ini"

' build the output file name from the path parameter and the report name
If Mid(destpath, Len(destpath), 1) <> "\" Then destpath = destpath & "\"
outputfile = destpath & reportname & ".pdf"

' PDF995 operates asynchronously. We need to determine when it is done so we can
' continue. This is done by creating a file and having PDF995 delete it using the
' ProcessPDF parameter in its ini file which runs a command when it is complete.

' save current settings from the PDF995.ini file
tmpoutputfile = ReadINIfile("PARAMETERS", "Output File", iniFileName)
tmpAutoLaunch = ReadINIfile("PARAMETERS", "Autolaunch", iniFileName)

' remove previous pdf if it exists
On Error Resume Next
Kill outputfile
On Error GoTo Cleanup

' setup new values in PDF995.ini
x = WritePrivateProfileString("PARAMETERS", "Output File", outputfile, iniFileName)
x = WritePrivateProfileString("PARAMETERS", "AutoLaunch", "0", iniFileName)

' change the default printer to PDF995
' if running on Access 2000 or earlier, comment out the next two lines
Set tmpPrinter = Application.Printer
Application.Printer = Application.Printers("PDF995")

'print the report
DoCmd.OpenReport reportname, acViewNormal, , strcriteria

' cleanup delay to allow PDF995 to finish up. When flagfile is nolonger present, PDF995 is done.
Sleep (10000)
maxwaittime = 300000 'If pdf995 isn't done in 5 min, quit anyway
Do While ReadINIfile("PARAMETERS", "Generating PDF CS", syncfile) = "1" And maxwaittime > 0
    Sleep (10000)
    maxwaittime = maxwaittime - 10000
Loop

' restore the original default printer and the PDF995.ini settings
Cleanup:
Sleep (10000)
x = WritePrivateProfileString("PARAMETERS", "Output File", tmpoutputfile, iniFileName)
x = WritePrivateProfileString("PARAMETERS", "AutoLaunch", tmpAutoLaunch, iniFileName)
x = WritePrivateProfileString("PARAMETERS", "Launch", "", iniFileName)
On Error Resume Next

' if running on Access 2000 or earlier, comment out the next line
Application.Printer = tmpPrinter

End Sub

Function ReadINIfile(sSection As String, sEntry As String, sFilename As String) As String
Dim x As Long
Dim sDefault As String
Dim sRetBuf As String, iLenBuf As Integer
Dim sValue As String

'Six arguments
'Explanation of arguments:
'sSection: ini file section (always between brackets)
'sEntry : word on left side of "=" sign
'sDefault$: value returned if function is unsuccessful
'sRetBuf$ : the value you're looking for will be copied to this buffer string
'iLenBuf% : Length in characters of the buffer string
'sFileName: Path to the ini file

sDefault$ = ""
sRetBuf$ = String$(256, 0)   '256 null characters
iLenBuf% = Len(sRetBuf$)
x = GetPrivateProfileString(sSection, sEntry, _
           sDefault$, sRetBuf$, iLenBuf%, sFilename)
ReadINIfile = Left$(sRetBuf$, x)

End Function


Now in theory i have everything to go into PDF production. One problem, I don't know how to!!!!!!
Looking at the PDF995 code it seems to focus on one report rather than the variables i am passing. I am hoping that the PDF code can be streamlined into the existing code.

regards and thanks in advance, vipa

0
vipa2000
Asked:
vipa2000
  • 28
  • 15
  • 12
1 Solution
 
rockiroadsCommented:
I guess you could just do this

change a call from

DoCmd.OutputTo acOutputReport, "rpt_plan_vs_res_herbs", acFormatSNP, "P:\Planning Engineers\weeklytest\" & "10weekherb" & ".snp", False


to

pdfWrite "rpt_plan_vs_res_herbs", "P:\Planning Engineers\weeklytest\" & "10weekherb"


that should then output your report to P:\

is that what u wanted?
0
 
rockiroadsCommented:
I just tried your code

note, , my pdf995 was installed in another dir, so I changed
iniFileName = "c:\pdf995\res\pdf995.ini"


I realise you have to add the suffiix

pdfWrite "rpt_plan_vs_res_herbs", "P:\Planning Engineers\weeklytest\" & "10weekherb" & ".pdf"

but it didnt produce anything
now that could be because of the location of the ini files
0
 
rockiroadsCommented:
What the code seems to be doing is modify the ini file so that it sets the name of the file to dump to

I stripped it down to be something like this, where this will print to pdf, but will prompt you.
I guess its a good test to see if it works

Public Sub CRTPDF()

    Dim prtCurrentPrinter As Printer

    Set prtCurrentPrinter = Application.Printer
    Application.Printer = Application.Printers("PDF995")

    DoCmd.OpenReport "ReportName", acViewNormal

    Application.Printer = prtCurrentPrinter

End Sub

0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
vipa2000Author Commented:
Hi  rockiroads, right makes sense so far. Where do i place the Public Sub CRTPDF() element? In my code or as a new function?
0
 
vipa2000Author Commented:
The reason i am asking is obviously because i have multiple reports to loop through and your code seems to use a static name. Am i correct. Also i need it to name the output files.
0
 
rockiroadsCommented:
ah ha

ok, I found my ini files and changed the path of the sync file

iniFileName = "C:\Program Files\pdf995\res\pdf995.ini"
syncfile = "C:\Program Files\pdf995\res\pdfsync.ini"


Now, the parameters

its name of report, directory to go to

the pdf file produced is the name of the report with extension .pdf


Now if you want it so that it uses your own name, try this

find this code
' build the output file name from the path parameter and the report name
If Mid(destpath, Len(destpath), 1) <> "\" Then destpath = destpath & "\"
outputfile = destpath & reportname & ".pdf"


and replace with this
if lcase$right$(destpath,4)) = ".pdf" then
    outputfile = destpath
else
    outputfile = destpath & ".pdf"
endif


Now whatever path/filename u specify, it will dump it to there - specifying suffix is now optional

e.g.

pdfWrite "rpt_plan_vs_res_herbs", "P:\Planning Engineers\weeklytest\" & "10weekherb" & ".pdf"

should produce in your P:\



0
 
rockiroadsCommented:
Vipa,

search for these ini files

pdf995.ini
pdfsync.ini

and change this

iniFileName = "C:\Program Files\pdf995\res\pdf995.ini"
syncfile = "C:\Program Files\pdf995\res\pdfsync.ini"

to point to that path

this has to be done to ensure the filename is stored in the ini file

Ive just tried this with the mods Ive made and its working fine


0
 
rockiroadsCommented:
spot the mistake!!!

if lcase$right$(destpath,4)) = ".pdf" then

missing bracker

If LCase$(Right$(destpath, 4)) = ".pdf" Then
0
 
vipa2000Author Commented:
can't find the pdfsync.ini file. Is this because i am using the freeware version currently?
0
 
rockiroadsCommented:
I dont know. You cant find it anywhere in your C drive?

this is what the contents look like

[Parameters]
Save As Display CS=0
Save As Displayed=0
Generating PDF CS=0
PS Creation Complete=1

0
 
vipa2000Author Commented:
rockiroads, i am confused, sorry. I thought initially you were tweaking elements of my code i.e steamlining. Now i don't know whether I am working with the PDF code or my code. I have printed it all out to try and piece it together, but to no avail. Ps you might have guessed i am not a programmer! I see the logic, but my jigsaw just doesn't fit together yet. Still on the 6-8 year old version i think! regards vipa.
0
 
vipa2000Author Commented:
found it - pdfsync.ini

D:\Documents and Settings\All Users\Application Data\pdf995
0
 
rockiroadsCommented:
I knew a Vipa once (well she changed her name!) and she was a very good programmer.
Dont worry about the programming level

What I have done is tweaked the code so that you pass in the report name and the full path of where you want the pdf file to go

You will need to do some programming :(
Dont worry its easy

below is the modified code, copy this code, overwrite yours with this (backup original if u so wish to)

my next post will explain what to do



Option Compare Database
Option Explicit

'Read INI settings
Declare Function GetPrivateProfileString Lib "kernel32" Alias _
   "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
   ByVal lpKeyName As Any, ByVal lpDefault As String, _
   ByVal lpReturnedString As String, ByVal nSize As Long, _
   ByVal lpFileName As String) As Long

'Write settings
Declare Function WritePrivateProfileString Lib "kernel32" Alias _
   "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
   ByVal lpKeyName As Any, ByVal lpString As Any, _
   ByVal lpFileName As String) As Long

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub pdfwrite(reportname As String, destpath As String, Optional strcriteria As String)

' Runs an Access report to PDF995 to create a pdf file from the report.
' Input parameters are the name of the report within the current database,
' the path for the output file, and an optional criteria for the report

' Be sure to check that the "Generating PDF CS" setting in pdfsync.ini is set to 0
' when pdf995 is idle. This codes uses that as a completion flag as it seems to be
' the most reliable indication that PDF995 is done writing the pdf file.


' Note: The application.printer object is not valid in Access 2000
' and earlier. In that case, set the printer in the report to pdf995
' and comment out the references herein to the application.printer

Dim syncfile As String, maxwaittime As Long
Dim iniFileName As String, tmpPrinter As Printer
Dim outputfile As String, x As Long
Dim tmpoutputfile As String, tmpAutoLaunch As String

' set the location of the PDF995.ini and the pdfsync files
iniFileName = "C:\Program Files\pdf995\res\pdf995.ini"
syncfile = "C:\Program Files\pdf995\res\pdfsync.ini"

' build the output file name from the path parameter and the report name
'If Mid(destpath, Len(destpath), 1) <> "\" Then destpath = destpath & "\"
If LCase$(Right$(destpath, 4)) = ".pdf" Then
    outputfile = destpath '& reportname & ".pdf"
Else
    outputfile = destpath & ".pdf"
End If

' PDF995 operates asynchronously. We need to determine when it is done so we can
' continue. This is done by creating a file and having PDF995 delete it using the
' ProcessPDF parameter in its ini file which runs a command when it is complete.

' save current settings from the PDF995.ini file
tmpoutputfile = ReadINIfile("PARAMETERS", "Output File", iniFileName)
tmpAutoLaunch = ReadINIfile("PARAMETERS", "Autolaunch", iniFileName)

' remove previous pdf if it exists
On Error Resume Next
Kill outputfile
On Error GoTo Cleanup

' setup new values in PDF995.ini
x = WritePrivateProfileString("PARAMETERS", "Output File", outputfile, iniFileName)
x = WritePrivateProfileString("PARAMETERS", "AutoLaunch", "0", iniFileName)

' change the default printer to PDF995
' if running on Access 2000 or earlier, comment out the next two lines
Set tmpPrinter = Application.Printer
Application.Printer = Application.Printers("PDF995")

'print the report
DoCmd.OpenReport reportname, acViewNormal, , strcriteria

' cleanup delay to allow PDF995 to finish up. When flagfile is nolonger present, PDF995 is done.
Sleep (10000)
maxwaittime = 300000 'If pdf995 isn't done in 5 min, quit anyway
Do While ReadINIfile("PARAMETERS", "Generating PDF CS", syncfile) = "1" And maxwaittime > 0
    Sleep (10000)
    maxwaittime = maxwaittime - 10000
Loop

' restore the original default printer and the PDF995.ini settings
Cleanup:
Sleep (10000)
x = WritePrivateProfileString("PARAMETERS", "Output File", tmpoutputfile, iniFileName)
x = WritePrivateProfileString("PARAMETERS", "AutoLaunch", tmpAutoLaunch, iniFileName)
x = WritePrivateProfileString("PARAMETERS", "Launch", "", iniFileName)
On Error Resume Next

' if running on Access 2000 or earlier, comment out the next line
Application.Printer = tmpPrinter

End Sub

Function ReadINIfile(sSection As String, sEntry As String, sFilename As String) As String
Dim x As Long
Dim sDefault As String
Dim sRetBuf As String, iLenBuf As Integer
Dim sValue As String

'Six arguments
'Explanation of arguments:
'sSection: ini file section (always between brackets)
'sEntry : word on left side of "=" sign
'sDefault$: value returned if function is unsuccessful
'sRetBuf$ : the value you're looking for will be copied to this buffer string
'iLenBuf% : Length in characters of the buffer string
'sFileName: Path to the ini file

sDefault$ = ""
sRetBuf$ = String$(256, 0)   '256 null characters
iLenBuf% = Len(sRetBuf$)
x = GetPrivateProfileString(sSection, sEntry, _
           sDefault$, sRetBuf$, iLenBuf%, sFilename)
ReadINIfile = Left$(sRetBuf$, x)

End Function
 
0
 
rockiroadsCommented:
ok, now your ini file was in D:\

find in the code above, these two lines

iniFileName = "C:\Program Files\pdf995\res\pdf995.ini"
syncfile = "C:\Program Files\pdf995\res\pdfsync.ini"


Now change the path to where yours is

i.e. in the case of your syncfile its

syncfile = "D:\Documents and Settings\All Users\Application Data\pdf995\pdfsync.ini"            

is the above the right path?
do the same for your other ini file


0
 
vipa2000Author Commented:
Looking good, but where does it get its data from the combobox?
0
 
rockiroadsCommented:
Lets take one example of your code that produces a report
e.g.
'preview report to apply filter
DoCmd.OpenReport "rpt_herb_exc_design&conagro_wklist", acViewPreview, , "Left([Funct# Location],6)='" & ctlComboBox.ItemData(i) & "'"

DoCmd.OutputTo acOutputReport, "rpt_herb_exc_design&conagro_wklist", acFormatSNP, "P:\Planning Engineers\weeklytest\" & ctlComboBox.ItemData(i) & ".snp", False

DoCmd.Close acReport, "rpt_herb_exc_design&conagro_wklist"


Now, this is printing report with criteria, what you are doing is opening report, with criteria   "Left([Funct# Location],6)='" & ctlComboBox.ItemData(i) & "'"
then dumping to snp

replace this call with this

pdfWrite "report name", "destination of pdf file", "criteria"

e.g.

pdfWrite "rpt_herb_exc_design&conagro_wklist",  "P:\Planning Engineers\weeklytest\" & ctlComboBox.ItemData(i),  "Left([Funct# Location],6)='" & ctlComboBox.ItemData(i) & "'"


May I suggest you try a simple report first
create a report (use report wizard, say call it VipaTest)

then try this in your code

Create a new module, and add this code in

public sub TestVipaReport

    pdfWrite "VipaTest", "P:\Planning Engineers\weeklytest\VipaTest.pdf"

end sub

then click your mouse somwhere in this produce, hit F5, this will run it.
Let it do its stuff then check that P:\ folder

good luck

0
 
vipa2000Author Commented:
Rig9ht

looking at your code above,i.e previous posting change this

'print the report
DoCmd.OpenReport reportname, acViewNormal, , strcriteria

to (substitute your code with your interpreted PDF995 code)

pdfWrite "rpt_herb_exc_design&conagro_wklist",  "P:\Planning Engineers\weeklytest\" & ctlComboBox.ItemData(i),  "Left([Funct# Location],6)='" & ctlComboBox.ItemData(i) & "'"
0
 
rockiroadsCommented:
If your current criteria works for running a report

i.e.  "Left([Funct# Location],6)='" & ctlComboBox.ItemData(i) & "'"

then this should work fine

In the code where you run the report, u call it there

The pdfWrite code has a DoCmd.OpenReport, do not touch that!!!

Basically, change the calls as in Private Sub Command10_Click()

0
 
vipa2000Author Commented:
Sorry rockiroads i have been tied up all morning. I have just created a new module and pasted the PDF code in. I tried to compile and it stalls on

, tmpPrinter As Printer

states user defined type not defined. I am now going through my code on the button i click and altering the calls to PDFwrite.

regards vipa.
0
 
vipa2000Author Commented:
my code is as follows attached to my button.

Private Sub Command10_Click()
On Error GoTo Error_Routine
   
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim RS As DAO.Recordset
    Dim ctlComboBox As Control
    Dim RS2 As DAO.Recordset           ' new recordset to output separate report
    Dim qdf2 As DAO.QueryDef

' the underlying recordset for the report is a query
    Set db = CurrentDb()
    Set qdf = db.QueryDefs("qry_herb_exc_design&conagro")
        qdf.Parameters(0) = Forms!frm_shedno_herb!cmb_shedherb.Value
    Set RS = qdf.OpenRecordset()
    Set ctlComboBox = Forms!frm_shedno_herb!cmb_shedherb
   
  Dim i As Integer   'loop counter for items selected from combobox
                     'enumerate through each of the items in combo box
         
For i = 0 To ctlComboBox.ListCount - 1

    ctlComboBox = cmb_shedherb.ItemData(i)
    ctlComboBox.Requery
    'preview report to apply filter
    DoCmd.OpenReport "rpt_herb_exc_design&conagro_wklist", acViewPreview, , "Left([Funct# Location],6)='" & ctlComboBox.ItemData(i) & "'"
    pdfwrite "rpt_herb_exc_design&conagro_wklist", "P:\Planning Engineers\weeklytest\" & ctlComboBox.ItemData(i) & ".pdf", False
    'close resource report
    DoCmd.Close acReport, "rpt_herb_exc_design&conagro_wklist"
   
Next i

RS.Close
Set RS = Nothing
Set ctlComboBox = Nothing
i = 0
   
    Set qdf2 = db.QueryDefs("qry_plan_vs_res_herbs")   ' assumes no parameters coming from a combo box
    Set RS2 = qdf.OpenRecordset()
   'preview report to apply filter
    DoCmd.OpenReport "rpt_plan_vs_res_herbs", acViewPreview  'output resource report via snapshot to web area
    pdfwrite "rpt_plan_vs_res_herbs", "P:\Planning Engineers\weeklytest\" & "10weekherb" & ".pdf", False
   'close resource report
    DoCmd.Close acReport, "rpt_plan_vs_res_herbs"

RS2.Close                                                 'closing code for second recordset
Set RS2 = Nothing

Exit_Continue:
        Exit Sub
Error_Routine:
        MsgBox "Error# " & Err.Number & " " & Err.Description
        Resume Exit_Continue
       

End Sub

0
 
vipa2000Author Commented:
The code is stalling because i havn't declared my printer????

back in the notes we had

Public Sub CRTPDF()

    Dim prtCurrentPrinter As Printer

    Set prtCurrentPrinter = Application.Printer
    Application.Printer = Application.Printers("PDF995")

    DoCmd.OpenReport "ReportName", acViewNormal

    Application.Printer = prtCurrentPrinter

End Sub

I don't need it all but where would i put the set element. In the command button code or in the module? (If of course i am supposed to have module!)

regards vipa
0
 
puppydogbuddyCommented:
Vipa,
Not for points (they belong to Rockiroads).

Place the code in a standard module without the open report command (as shown below):

Public Sub CRTPDF()

    Dim prtCurrentPrinter As Printer

    Set prtCurrentPrinter = Application.Printer
    Application.Printer = Application.Printers("PDF995")

    Application.Printer = prtCurrentPrinter

End Sub
0
 
puppydogbuddyCommented:
Then modify the code in your program as follows:

Change this:
      pdfwrite "rpt_plan_vs_res_herbs", "P:\Planning Engineers\weeklytest\" & "10weekherb" & ".pdf", False
   'close resource report

to this:
CRTPDF "rpt_plan_vs_res_herbs", "P:\Planning Engineers\weeklytest\" & "10weekherb" & ".pdf", False
   'close resource report
0
 
puppydogbuddyCommented:
oops! that won't work....try it this way, calling the CRTPDF function from where the format parameter goes:

DoCmd.OutputTo acOutputReport, "rpt_herb_exc_design&conagro_wklist",CRTPDF, "P:\Planning Engineers\weeklytest\" & ctlComboBox.ItemData(i) & ".pdf", False


If that doesn't work, try using the DoCmd.SendObject command syntax in lieu of DoCmd.OutputTo acOutputReport.

Hope this helps.
0
 
rockiroadsCommented:
Vipa, sorry for the delay. I left for the USA back on the 6th and have been unable to get to EE.

The CRTPDF was test code to demonstrate the use of printing to PDF995

Now, since u are having problems with the line

As Printer

this suggests u are perhaps missing a reference or something, not sure

try this

Public Sub CRTPDF()

'Define as variant
    Dim prtCurrentPrinter

    Set prtCurrentPrinter = Application.Printer
'If this fails, then try this line
    Set prtCurrentPrinter = Application.Printers(0)

    Application.Printer = Application.Printers("PDF995")

    DoCmd.OpenReport "rpt_herb_exc_design&conagro_wklist", acViewNormal

    Application.Printer = prtCurrentPrinter

End Sub


if this works, then u should be able to use pdfWrite
0
 
vipa2000Author Commented:
rockiroads, puppydogbuddy, sorry for delay i have been away for a few days and then problems at work.

puppydogbuddy i put the following code into a module called module 2 and tried to compile. It still stalled on ,    tmpPrinter As Printer       ( in module1) error not defined. Module1 is the holding pot for the PDF code.

Public Sub CRTPDF()

    Dim prtCurrentPrinter As Printer

    Set prtCurrentPrinter = Application.Printer
    Application.Printer = Application.Printers("PDF995")

    DoCmd.OpenReport "ReportName", acViewNormal

    Application.Printer = prtCurrentPrinter

End Sub

rockiroads i created a new module with the code

Public Sub CRTPDF()

'Define as variant
    Dim prtCurrentPrinter

    Set prtCurrentPrinter = Application.Printer
'If this fails, then try this line
    Set prtCurrentPrinter = Application.Printers(0)

    Application.Printer = Application.Printers("PDF995")

    DoCmd.OpenReport "rpt_herb_exc_design&conagro_wklist", acViewNormal

    Application.Printer = prtCurrentPrinter

End Sub

And tried to run using both Set prtCurrentPrinter variants. States member not defined.

I will paste next my code for my button and my code for my PDF printer just to ensure we are looking at the same data.

thanks for the ongoing help, vipa

0
 
vipa2000Author Commented:
module1 the code for the pdfprinter

Option Compare Database

Option Explicit

'Read INI settings
Declare Function GetPrivateProfileString Lib "kernel32" Alias _
   "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
   ByVal lpKeyName As Any, ByVal lpDefault As String, _
   ByVal lpReturnedString As String, ByVal nSize As Long, _
   ByVal lpFileName As String) As Long

'Write settings
Declare Function WritePrivateProfileString Lib "kernel32" Alias _
   "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
   ByVal lpKeyName As Any, ByVal lpString As Any, _
   ByVal lpFileName As String) As Long

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub pdfwrite(reportname As String, destpath As String, Optional strcriteria As String)

' Runs an Access report to PDF995 to create a pdf file from the report.
' Input parameters are the name of the report within the current database,
' the path for the output file, and an optional criteria for the report

' Be sure to check that the "Generating PDF CS" setting in pdfsync.ini is set to 0
' when pdf995 is idle. This codes uses that as a completion flag as it seems to be
' the most reliable indication that PDF995 is done writing the pdf file.


' Note: The application.printer object is not valid in Access 2000
' and earlier. In that case, set the printer in the report to pdf995
' and comment out the references herein to the application.printer

Dim syncfile As String, maxwaittime As Long
Dim iniFileName As String, tmpPrinter As Printer
Dim outputfile As String, x As Long
Dim tmpoutputfile As String, tmpAutoLaunch As String

' set the location of the PDF995.ini and the pdfsync files
iniFileName = "C:\Program Files\pdf995\res\pdf995.ini"
syncfile = "D:\Documents and Settings\All Users\Application Data\pdf995\pdfsync.ini"

' build the output file name from the path parameter and the report name
'If Mid(destpath, Len(destpath), 1) <> "\" Then destpath = destpath & "\"
If LCase$(Right$(destpath, 4)) = ".pdf" Then
    outputfile = destpath '& reportname & ".pdf"
Else
    outputfile = destpath & ".pdf"
End If

' PDF995 operates asynchronously. We need to determine when it is done so we can
' continue. This is done by creating a file and having PDF995 delete it using the
' ProcessPDF parameter in its ini file which runs a command when it is complete.

' save current settings from the PDF995.ini file
tmpoutputfile = ReadINIfile("PARAMETERS", "Output File", iniFileName)
tmpAutoLaunch = ReadINIfile("PARAMETERS", "Autolaunch", iniFileName)

' remove previous pdf if it exists
On Error Resume Next
Kill outputfile
On Error GoTo Cleanup

' setup new values in PDF995.ini
x = WritePrivateProfileString("PARAMETERS", "Output File", outputfile, iniFileName)
x = WritePrivateProfileString("PARAMETERS", "AutoLaunch", "0", iniFileName)

' change the default printer to PDF995
' if running on Access 2000 or earlier, comment out the next two lines
Set tmpPrinter = Application.Printer
Application.Printer = Application.Printers("PDF995")

'print the report
DoCmd.OpenReport reportname, acViewNormal, , strcriteria

' cleanup delay to allow PDF995 to finish up. When flagfile is nolonger present, PDF995 is done.
Sleep (10000)
maxwaittime = 300000 'If pdf995 isn't done in 5 min, quit anyway
Do While ReadINIfile("PARAMETERS", "Generating PDF CS", syncfile) = "1" And maxwaittime > 0
    Sleep (10000)
    maxwaittime = maxwaittime - 10000
Loop

' restore the original default printer and the PDF995.ini settings
Cleanup:
Sleep (10000)
x = WritePrivateProfileString("PARAMETERS", "Output File", tmpoutputfile, iniFileName)
x = WritePrivateProfileString("PARAMETERS", "AutoLaunch", tmpAutoLaunch, iniFileName)
x = WritePrivateProfileString("PARAMETERS", "Launch", "", iniFileName)
On Error Resume Next

' if running on Access 2000 or earlier, comment out the next line
Application.Printer = tmpPrinter

End Sub

Function ReadINIfile(sSection As String, sEntry As String, sFilename As String) As String
Dim x As Long
Dim sDefault As String
Dim sRetBuf As String, iLenBuf As Integer
Dim sValue As String

'Six arguments
'Explanation of arguments:
'sSection: ini file section (always between brackets)
'sEntry : word on left side of "=" sign
'sDefault$: value returned if function is unsuccessful
'sRetBuf$ : the value you're looking for will be copied to this buffer string
'iLenBuf% : Length in characters of the buffer string
'sFileName: Path to the ini file

sDefault$ = ""
sRetBuf$ = String$(256, 0)   '256 null characters
iLenBuf% = Len(sRetBuf$)
x = GetPrivateProfileString(sSection, sEntry, _
           sDefault$, sRetBuf$, iLenBuf%, sFilename)
ReadINIfile = Left$(sRetBuf$, x)

End Function


0
 
vipa2000Author Commented:
code attached to the button on my form

Private Sub Command10_Click()
On Error GoTo Error_Routine
   
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim RS As DAO.Recordset
    Dim ctlComboBox As Control
    Dim RS2 As DAO.Recordset           ' new recordset to output separate report
    Dim qdf2 As DAO.QueryDef

' the underlying recordset for the report is a query
    Set db = CurrentDb()
    Set qdf = db.QueryDefs("qry_herb_exc_design&conagro")
        qdf.Parameters(0) = Forms!frm_shedno_herb!cmb_shedherb.Value
    Set RS = qdf.OpenRecordset()
    Set ctlComboBox = Forms!frm_shedno_herb!cmb_shedherb
   
  Dim i As Integer   'loop counter for items selected from combobox
                     'enumerate through each of the items in combo box
         
For i = 0 To ctlComboBox.ListCount - 1

    ctlComboBox = cmb_shedherb.ItemData(i)
    ctlComboBox.Requery
    'preview report to apply filter
    DoCmd.OpenReport "rpt_herb_exc_design&conagro_wklist", acViewPreview, , "Left([Funct# Location],6)='" & ctlComboBox.ItemData(i) & "'"
    pdfwrite "rpt_herb_exc_design&conagro_wklist", "P:\Planning Engineers\weeklytest\" & ctlComboBox.ItemData(i) & ".pdf", False
    'close resource report
    DoCmd.Close acReport, "rpt_herb_exc_design&conagro_wklist"
   
Next i

RS.Close
Set RS = Nothing
Set ctlComboBox = Nothing
i = 0
   
    Set qdf2 = db.QueryDefs("qry_plan_vs_res_herbs")   ' assumes no parameters coming from a combo box
    Set RS2 = qdf.OpenRecordset()
   'preview report to apply filter
    DoCmd.OpenReport "rpt_plan_vs_res_herbs", acViewPreview  'output resource report via snapshot to web area
    pdfwrite "rpt_plan_vs_res_herbs", "P:\Planning Engineers\weeklytest\" & "10weekherb" & ".pdf", False
   'close resource report
    DoCmd.Close acReport, "rpt_plan_vs_res_herbs"

RS2.Close                                                 'closing code for second recordset
Set RS2 = Nothing

Exit_Continue:
        Exit Sub
Error_Routine:
        MsgBox "Error# " & Err.Number & " " & Err.Description
        Resume Exit_Continue
       

End Sub
0
 
vipa2000Author Commented:
food for thought, been a non programmer!

initially i thought puppydogbuddy was on to something and seems logical, but rockiroads the last bit of code you posted, does or could this be declared in the button code i.e the 'Set prtCurrentPrinter' elements . The code looks as though it is nearly there.

over to the experts, vipa
0
 
vipa2000Author Commented:
I am using Access2000 and noticed this rem statement in the pdf code. The source of the problem?

' Note: The application.printer object is not valid in Access 2000
' and earlier. In that case, set the printer in the report to pdf995
' and comment out the references herein to the application.printer
0
 
puppydogbuddyCommented:
Vipa, Rockiroads,
I think Rockiroads code will work if you go back and comment out the two lines noted by Rockiroads, himself.

' change the default printer to PDF995
' if running on Access 2000 or earlier, comment out the next two lines
Set tmpPrinter = Application.Printer
Application.Printer = Application.Printers("PDF995")
0
 
vipa2000Author Commented:
in the module1 i have rem'd out the above statements and another one referenced in the code that should be turned off. i have opened the reports and saved with new default printerembedded.

i am just going to try "remming" the statement          tmpPrinter As Printer as it appears no longer valid in the button code.
0
 
vipa2000Author Commented:
Thank you both, now generating pdf's and it's slick. Response seems slow but i think that could be because i am on the trial version of pdf995. I am having issues with work and the use of globally agreed software, but that's another problem. For info, now i have a module i assume i can alter my code in other forms to do the same as this form?

thanks again, vipa
0
 
puppydogbuddyCommented:
VIpa,
Yes, you can reference the central module from anywhere in that MDB file.

                                      PDB
0
 
vipa2000Author Commented:
Out of interest i think there is bug in the code. When i ran it with the new data from other forms, the code stalled on
Kill outputfile within the code below. The path shown whilst debugging was fine (sound like i know what i am doing) the error dialogue box stated it couldn't find the file. In the end i renamed a PDf file to the same as i wanted and re-run the code, it worked fine. So long as all the files exist in the directory before you run then it will work.

Sub pdfwrite(reportname As String, destpath As String, Optional strcriteria As String)

' Runs an Access report to PDF995 to create a pdf file from the report.
' Input parameters are the name of the report within the current database,
' the path for the output file, and an optional criteria for the report

' Be sure to check that the "Generating PDF CS" setting in pdfsync.ini is set to 0
' when pdf995 is idle. This codes uses that as a completion flag as it seems to be
' the most reliable indication that PDF995 is done writing the pdf file.


' Note: The application.printer object is not valid in Access 2000
' and earlier. In that case, set the printer in the report to pdf995
' and comment out the references herein to the application.printer

Dim syncfile As String, maxwaittime As Long
Dim iniFileName As String 'tmpPrinter As Printer
Dim outputfile As String, x As Long
Dim tmpoutputfile As String, tmpAutoLaunch As String

' set the location of the PDF995.ini and the pdfsync files
iniFileName = "C:\Program Files\pdf995\res\pdf995.ini"
syncfile = "D:\Documents and Settings\All Users\Application Data\pdf995\pdfsync.ini"

' build the output file name from the path parameter and the report name
'If Mid(destpath, Len(destpath), 1) <> "\" Then destpath = destpath & "\"
If LCase$(Right$(destpath, 4)) = ".pdf" Then
    outputfile = destpath '& reportname & ".pdf"
Else
    outputfile = destpath & ".pdf"
End If

' PDF995 operates asynchronously. We need to determine when it is done so we can
' continue. This is done by creating a file and having PDF995 delete it using the
' ProcessPDF parameter in its ini file which runs a command when it is complete.

' save current settings from the PDF995.ini file
tmpoutputfile = ReadINIfile("PARAMETERS", "Output File", iniFileName)
tmpAutoLaunch = ReadINIfile("PARAMETERS", "Autolaunch", iniFileName)

' remove previous pdf if it exists
On Error Resume Next
Kill outputfile
On Error GoTo Cleanup

' setup new values in PDF995.ini
x = WritePrivateProfileString("PARAMETERS", "Output File", outputfile, iniFileName)
x = WritePrivateProfileString("PARAMETERS", "AutoLaunch", "0", iniFileName)

' change the default printer to PDF995
' if running on Access 2000 or earlier, comment out the next two lines
'Set tmpPrinter = Application.Printer
'Application.Printer = Application.Printers("PDF995")

'print the report
DoCmd.OpenReport reportname, acViewNormal, , strcriteria

' cleanup delay to allow PDF995 to finish up. When flagfile is nolonger present, PDF995 is done.
Sleep (10000)
maxwaittime = 300000 'If pdf995 isn't done in 5 min, quit anyway
Do While ReadINIfile("PARAMETERS", "Generating PDF CS", syncfile) = "1" And maxwaittime > 0
    Sleep (10000)
    maxwaittime = maxwaittime - 10000
Loop

' restore the original default printer and the PDF995.ini settings
Cleanup:
Sleep (10000)
x = WritePrivateProfileString("PARAMETERS", "Output File", tmpoutputfile, iniFileName)
x = WritePrivateProfileString("PARAMETERS", "AutoLaunch", tmpAutoLaunch, iniFileName)
x = WritePrivateProfileString("PARAMETERS", "Launch", "", iniFileName)
On Error Resume Next

' if running on Access 2000 or earlier, comment out the next line
'Application.Printer = tmpPrinter

End Sub
0
 
puppydogbuddyCommented:
Vipa,
try changing this:

' remove previous pdf if it exists
On Error Resume Next
Kill outputfile
On Error GoTo Cleanup

to this:
' remove previous pdf if it exists
On Error Resume Next
If Len(outputfile) > 0 then
    Kill outputfile
End If
On Error GoTo Cleanup

0
 
vipa2000Author Commented:
Same error unfortunately.
0
 
puppydogbuddyCommented:
comment out this line from the code

' if running on Access 2000 or earlier, comment out the next line
Application.Printer = tmpPrinter   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

0
 
vipa2000Author Commented:
puppydogbuddy, that was the extra line that i had already spotted and 'remarked' out, in addition to the ones you had told me to rem out.
0
 
puppydogbuddyCommented:
At the point of error, go to the immediate window [CTrl+G]:

?outputfile

?len(outputfile)

?tmpPrinter
0
 
vipa2000Author Commented:
?outputfile
P:\Planning Engineers\Weekly Reports\120843.pdf

?len(outputfile)
 47

?tmpPrinter
no answer given. This is correct isn't it?
0
 
puppydogbuddyCommented:
Vipa,
All answers correct.  Try this:

If Len(outputfile) > 0 Then
           Call Kill(destpath & "\*.pdf")
End If
0
 
vipa2000Author Commented:
thought it did. put new code in, stalls on Call Kill, states file not found.

?destpath   displays
P:\Planning Engineers\Weekly Reports\120843.pdf
0
 
puppydogbuddyCommented:
Vipa,
Try this:

If Len(outputfile) > 0 Then
           ChDir "P:\Planning Engineers\Weekly Reports\"
           Call Kill(*.pdf")
End If
0
 
vipa2000Author Commented:
PDB i think there isa typo on the call kill line, doesn't like it
0
 
puppydogbuddyCommented:
Vipa,
I left a quote out. Change this:  Call Kill(*.pdf")

                                  to this:
                                               Call Kill("*.pdf")



if it doesn't work, go to immediate window:
  ?  Dir
0
 
vipa2000Author Commented:
Stalls on kill element again.

? Dir gives Runtime error 5. invalid procedure or call.
0
 
puppydogbuddyCommented:
Try it this way

If Len(Dir$("P:\Planning Engineers\Weekly Reports\*.pdf")) > 0 Then
            Kill("P:\Planning Engineers\Weekly Reports\*.pdf")
End If

0
 
vipa2000Author Commented:
puppydogbuddy apologies for slow response, daughter has been ill and this is the first chance. I don't get an error message now, but i couldn't quite work out what was going on until i kept refreshing the output directory. The code is overwriting the last pdf file so i only ever get one output file instead of 30 ish

regards vipa
0
 
puppydogbuddyCommented:
vipa,
That is because I am using the * (wildcard) symbol, which erases everything in that directory with an extension of .pdf.  You don't have to use the wildcard.  You can use a specific file name or perhaps we can add a date condition to the expression to erase everything prior to a certain date.  Can you provide me with the criteria that could be use to programmatically determine which pdf files you want to erase?
                                           PDB
0
 
vipa2000Author Commented:
Mmmm. Could be one to think about this. Could you simply code it so that it overwrites a file of the same name? i.e 120710 is over writen with 120710. The issue here is i run this/these reports up to several times a day dependent on changes within the database - SAP. I could list all the file names, here is an example based on the snp output type we had originally.  The list would not be much bigger than this.

10weekherb.snp
120209.snp
120215.snp
120260.snp
120354.snp
120414.snp
120429.snp
120455.snp
120469.snp
120520.snp
120529.snp
120548.snp
120550.snp
120580.snp
120594.snp
120607.snp
120610.snp
120614.snp
120615.snp
120621.snp
120623.snp
120624.snp
120632.snp
120638.snp
120701.snp
120705.snp
120709.snp
120710.snp
120719.snp
120800.snp
120802.snp
120819.snp
120829.snp
120856.snp
120905.snp
8489.snp
CONBILD.snp
CONCRS.snp
CONELECT.snp
CONFAB.snp
CONSTEEL.snp
CONVALVE.snp
ESTHERB.snp
ESTINS.snp
INSPECT.pdf
INSPECT.snp
0
 
puppydogbuddyCommented:
Vipa,
Hope your daughter is feeling better.
Afterexecuting the code below, go to immediate window
?Dir(KillFile)
?KillFile

--------------------------------------------------------------------------------------------
Let's try this:
Dim KillFile As String                                   'the file to be erased if a duplicate exists

KillFile = outputfile

If Len(Dir$(KillFile)) > 0 Then                  'check to see if duplicate file exists
            Kill KillFile
End If
0
 
vipa2000Author Commented:
Looks like you have cracked it. files created if directory empty and over written if already present . As requested though the results of

?Dir(KillFile)
gives runtime error 13

?KillFile
gives a blank line.

thank you again, regards vipa. ps nearly forgot, daughter up and about after antibiotics kicked in.
0
 
puppydogbuddyCommented:
Glad its working now and that your daughter is ok.   The blank line and runtime error are what would be expected if inquiry done after file has been erased.
0
 
vipa2000Author Commented:
final code is as below.


Option Compare Database

Option Explicit

'Read INI settings
Declare Function GetPrivateProfileString Lib "kernel32" Alias _
   "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
   ByVal lpKeyName As Any, ByVal lpDefault As String, _
   ByVal lpReturnedString As String, ByVal nSize As Long, _
   ByVal lpFileName As String) As Long

'Write settings
Declare Function WritePrivateProfileString Lib "kernel32" Alias _
   "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
   ByVal lpKeyName As Any, ByVal lpString As Any, _
   ByVal lpFileName As String) As Long

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub pdfwrite(reportname As String, destpath As String, Optional strcriteria As String)

' Runs an Access report to PDF995 to create a pdf file from the report.
' Input parameters are the name of the report within the current database,
' the path for the output file, and an optional criteria for the report

' Be sure to check that the "Generating PDF CS" setting in pdfsync.ini is set to 0
' when pdf995 is idle. This codes uses that as a completion flag as it seems to be
' the most reliable indication that PDF995 is done writing the pdf file.


' Note: The application.printer object is not valid in Access 2000
' and earlier. In that case, set the printer in the report to pdf995
' and comment out the references herein to the application.printer

Dim syncfile As String, maxwaittime As Long
Dim iniFileName As String 'tmpPrinter As Printer
Dim outputfile As String, x As Long
Dim tmpoutputfile As String, tmpAutoLaunch As String
Dim KillFile As String

' set the location of the PDF995.ini and the pdfsync files
iniFileName = "C:\Program Files\pdf995\res\pdf995.ini"
syncfile = "D:\Documents and Settings\All Users\Application Data\pdf995\pdfsync.ini"

' build the output file name from the path parameter and the report name
'If Mid(destpath, Len(destpath), 1) <> "\" Then destpath = destpath & "\"
If LCase$(Right$(destpath, 4)) = ".pdf" Then
    outputfile = destpath '& reportname & ".pdf"
Else
    outputfile = destpath & ".pdf"
End If

' PDF995 operates asynchronously. We need to determine when it is done so we can
' continue. This is done by creating a file and having PDF995 delete it using the
' ProcessPDF parameter in its ini file which runs a command when it is complete.

' save current settings from the PDF995.ini file
tmpoutputfile = ReadINIfile("PARAMETERS", "Output File", iniFileName)
tmpAutoLaunch = ReadINIfile("PARAMETERS", "Autolaunch", iniFileName)

' remove previous pdf if it exists
On Error Resume Next
KillFile = outputfile

If Len(Dir$(KillFile)) > 0 Then                  'check to see if duplicate file exists
            Kill KillFile
End If
On Error GoTo Cleanup

' setup new values in PDF995.ini
x = WritePrivateProfileString("PARAMETERS", "Output File", outputfile, iniFileName)
x = WritePrivateProfileString("PARAMETERS", "AutoLaunch", "0", iniFileName)

' change the default printer to PDF995
' if running on Access 2000 or earlier, comment out the next two lines
'Set tmpPrinter = Application.Printer
'Application.Printer = Application.Printers("PDF995")

'print the report
DoCmd.OpenReport reportname, acViewNormal, , strcriteria

' cleanup delay to allow PDF995 to finish up. When flagfile is nolonger present, PDF995 is done.
Sleep (10000)
maxwaittime = 300000 'If pdf995 isn't done in 5 min, quit anyway
Do While ReadINIfile("PARAMETERS", "Generating PDF CS", syncfile) = "1" And maxwaittime > 0
    Sleep (10000)
    maxwaittime = maxwaittime - 10000
Loop

' restore the original default printer and the PDF995.ini settings
Cleanup:
Sleep (10000)
x = WritePrivateProfileString("PARAMETERS", "Output File", tmpoutputfile, iniFileName)
x = WritePrivateProfileString("PARAMETERS", "AutoLaunch", tmpAutoLaunch, iniFileName)
x = WritePrivateProfileString("PARAMETERS", "Launch", "", iniFileName)
On Error Resume Next

' if running on Access 2000 or earlier, comment out the next line
'Application.Printer = tmpPrinter

End Sub

Function ReadINIfile(sSection As String, sEntry As String, sFilename As String) As String
Dim x As Long
Dim sDefault As String
Dim sRetBuf As String, iLenBuf As Integer
Dim sValue As String

'Six arguments
'Explanation of arguments:
'sSection: ini file section (always between brackets)
'sEntry : word on left side of "=" sign
'sDefault$: value returned if function is unsuccessful
'sRetBuf$ : the value you're looking for will be copied to this buffer string
'iLenBuf% : Length in characters of the buffer string
'sFileName: Path to the ini file

sDefault$ = ""
sRetBuf$ = String$(256, 0)   '256 null characters
iLenBuf% = Len(sRetBuf$)
x = GetPrivateProfileString(sSection, sEntry, _
           sDefault$, sRetBuf$, iLenBuf%, sFilename)
ReadINIfile = Left$(sRetBuf$, x)

End Function


0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

  • 28
  • 15
  • 12
Tackle projects and never again get stuck behind a technical roadblock.
Join Now