PDF Creator VBA (1 Viewer)

Sniper-BoOyA-

Registered User.
Local time
Today, 05:29
Joined
Jun 15, 2010
Messages
204
Good Afternoon people,

I am trying to get a hand of a few things when it comes to Access and VBA. There is just one thing i can not seem to figure out.

Ive got a database which is made by a man who is no longer with us, and he made a button which opens a report, gives the printer an order to print it, and also saves the report as a pdf file.

The code beind that button is:

Code:
Private Sub cmdafdrtoetsN1_Click()
On Error GoTo Err_cmdafdrtoetsN1_Click
    
    Dim prt As Printer
    Dim i As Long
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim rst2 As DAO.Recordset
    Dim strNaam As String
    Dim strSubPad As String
    Dim strPad As String
    Dim strRapport As String
    Set db = CurrentDb
    Set rst = db.OpenRecordset("contact", dbOpenDynaset)
    strRapport = "raptoetsingN1"
    Set prt = Application.Printer
    Application.Printer = Printers("PDFCreator")
    'patch which will be used to save the .pfd    
    '(Folder current database)
    'strPad = CurrentProject.Path
    PDF_Start
    strNaam = rst!opdrachtnr
    strSubPad = Left(strNaam, 2)
    strPad = "G:\" & strSubPad & "\" & strNaam & "\" & "Acrobat\"
    strNaam = "LS_Asfalt_Toetsing_(N1)" & strNaam
            If AfdrukkenRapport(strRapport, strNaam, strPad) = 1 Then
            rst.MoveNext
        Else
        End If
    PDF_Stop
    Application.Printer = prt
    DoCmd.OpenReport strRapport, acViewNormal
Exit_cmdafdrtoetsN1_Click:
    Exit Sub
Err_cmdafdrtoetsN1_Click:
    MsgBox "Fout: " & Err.Number & vbNewLine & Err.Description, vbExclamation, "cmdafdrtoetsN1_Click"
    Resume Exit_cmdafdrtoetsN1_Click
End Sub

What i am trying to do is to split the 2 functions and make one button to print it, and one button to save it as a pdf. But i cant seem to understand what happends in this code.

Is there anyone who is so kind to explain it a little bit so i can split the thing?

Cheers!
 

ions

Access User
Local time
Today, 05:29
Joined
May 23, 2004
Messages
785
This part is your PDF part. He is printing to PDF Creator.

Application.Printer = Printers("PDFCreator")
'patch which will be used to save the .pfd
'(Folder current database)
'strPad = CurrentProject.Path
PDF_Start
strNaam = rst!opdrachtnr
strSubPad = Left(strNaam, 2)
strPad = "G:\" & strSubPad & "\" & strNaam & "\" & "Acrobat\"
strNaam = "LS_Asfalt_Toetsing_(N1)" & strNaam
If AfdrukkenRapport(strRapport, strNaam, strPad) = 1 Then
rst.MoveNext
Else
End If
PDF_Stop
 

boblarson

Smeghead
Local time
Today, 05:29
Joined
Jan 12, 2001
Messages
32,059
As ions said - the function is actually printing to a pdf using the PDF Creator printer driver and as such the two operations cannot be separated.
 

ions

Access User
Local time
Today, 05:29
Joined
May 23, 2004
Messages
785
Bob why can't they be seperated?

He switched back to the default printer after the PDF_Stop and is doing a normal print of the Report.

PDF_Start and PDF_Stop look like subs without arguments.

Original Poster if you are using Access 2007 you can print PDF using the Docmd object.

Prior to 2007 I used Stephen Lebans PDF code.
 

Sniper-BoOyA-

Registered User.
Local time
Today, 05:29
Joined
Jun 15, 2010
Messages
204
Sorry for the late reply. I fixed it by making a 2nd button, and giving it the VBA code IONS mentioned. And it works like a charm.

Now i have two buttons, one send it to the printer, and the other one makes a .pdf file.

Problem solved!

Thanks for all the replies / help. And again, sorry for the late reply.
 

smig

Registered User.
Local time
Today, 15:29
Joined
Nov 25, 2009
Messages
2,209
just a small fix:
one send it to the default pinter, and the other send it to the PDFCreator printer :D

PDFcreator is a PDF printer
 

Users who are viewing this thread

Top Bottom