Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print existing PDF's in Access 1

Status
Not open for further replies.

demills

Programmer
Jun 14, 2002
10
CA
Hi All -

Am having a problem printing a large collection of existing PDF files in Access. Have used the folowing code in a loop feeding it filenames and things seem to work ok, except not all PDF files print. It tends to print a group of say 4 or 5 documents, skips some, prints some more, and so on. It also leaves multiple copies of Adobe open but still closes the majority of them. I'm thinking it must have something to do with the speed it is sending the commands to Adobe. I tried setting the wait arguments for sendkeys to true and putting a delay loop in, nothing seemed to help. Anyone have any ideas?

rs.MoveFirst
While i <= lNumrec
sFilePath = "\\glfsmalld2\MapX\Images\" + rs.Fields("clientnum").Value + "\"

sFileName = rs.Fields("clientnum").Value & rs.Fields("date").Value & ".PDF"

'print PDF
Application.FollowHyperlink sFilePath + sFileName
SendKeys "%(FP)"
SendKeys "~", True
SendKeys "^q" 'Quits Adobe

i = i + 1
rs.MoveNext
Wend
 
have you looked at doevents along with the wait ?

however,

Set a reference to the Acrobat adobe acrobat browser control

and you can then use code such as this

Code:
Sub pdf()
Set AcroPDF = CreateObject("acroPDF.PDF")

Dim aPDF As AcroPDF
Set aPDF = New AcroPDF

aPDF.LoadFile ("c:test.pdf")
aPDF.printAll
End Sub

just change the above to fit into your loop

Chance,

F, G + B
 
ignore this line Set AcroPDF = CreateObject("acroPDF.PDF") my copy paste error

Chance,

F, G + B
 
Thanks Chance -

I gave it a try. I added a Reference to the Adobe browser and added your code. It doesn't give me any errors and executes each line, but it also doesn't seem to do anything. Here's my whole Subroutine.

Sub PastDue

Dim db As Database
Dim rs As Recordset
Dim sfile As String
Dim lNumrec As Long
Dim i As Integer
Dim sFilePath As String
Dim sFileStr As String

Dim aPDF As AcroPDF
Set aPDF = New AcroPDF

Set db = CurrentDb
Set rs = db.OpenRecordset("Billing - clients past due")

rs.MoveLast
lNumrec = rs.RecordCount

i = 1
rs.MoveFirst
While i <= lNumrec
'Print image of bills
sFilePath = "\\glfsmalld2\MapX\Images\" + rs.Fields("clientnum").Value + "\"

If rs.Fields("date").Value = #6/18/2004# Then
sFileStr = " "
Else
sFileStr = "-Bill "
End If

sfile = sFilePath + rs.Fields("clientnum").Value + sFileStr + rs.Fields("date").Value + ".PDF"

'print PDF
aPDF.LoadFile (sfile)
aPDF.printAll

i = i + 1
rs.MoveNext
Wend
Set rs = Nothing
Set aPDF = Nothing
db.Close

MsgBox "Finished Printing Past Due Bills"

Exit_btnPastDue_Click:
Exit Sub

Err_btnPastDue_Click:
MsgBox "form:acnt main - btnPastDue:" + Err.Description
Resume Exit_btnPastDue_Click

End Sub
 
also, bit messy but saw this on a VB forum

Code:
Sub one()
print_pdf ("C:\Test.pdf")

End Sub

Sub print_pdf(XsomeFile As String)
    DoEvents
    Shell "C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe /p /h " & XsomeFile, vbHide
End Sub


Chance,

F, G + B
 
Thanks for your help Chance - Got it to work using last suggestion. Like you said a bit messy but it works.

DoEvents
Shell "C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe /p /h """ & sfile & """"
 

Also check out what johnwm says at how to print a file from VB thread222-1251267
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top