?
Solved

MS Access vba Print  PDF First page only

Posted on 2017-05-16
16
Medium Priority
?
75 Views
Last Modified: 2017-05-19
Hi, I have this code below works fine BUT the problem is; it's doing PDF for all the pages, what I need to do is to make PDF only for the first page  

Private Sub BtnPdf_Click()
Dim FileName As String
Dim FilePath As String
Dim inStkN As Integer
Dim frm As Form
Set frm = Screen.ActiveForm
inStkN = Me.StkN
FileName = "Transf-" & inStkN
FilePath = "C:\Users\orly\Desktop\FolderName\"
    frm.Filter = "StkID = " & frm.StkID
    frm.FilterOn = True
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.OutputTo acOutputForm, "Msg_FrmC", acFormatPDF, FilePath & FileName & ".pdf", True
    frm.FilterOn = False
End Sub
0
Comment
Question by:Ronald Malk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
16 Comments
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 42136520
HI,

One way would be to have a pdf printer and then use
DoCmd.PrintOut acPages, 1, 1

Open in new window

Caveat:
The report needs to be opened before printing

Regards
0
 

Author Comment

by:Ronald Malk
ID: 42136532
Thanks for the reply, Can you please add it for me in my code that's what I did but I'm having error
Private Sub BtnPdf_Click()
Dim FileName As String
Dim FilePath As String
Dim inStkN As Integer
Dim frm As Form
Set frm = Screen.ActiveForm
inStkN = Me.StkN
FileName = "Transf-" & inStkN
FilePath = "C:\Users\orly\Desktop\FolderName\"
    frm.Filter = "StkID = " & frm.StkID
    frm.FilterOn = True
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.PrintOut acPages, 1, 1, "Msg_FrmC", acFormatPDF, FilePath & FileName & ".pdf", True   '<<Error here
    frm.FilterOn = False
End Sub
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 42136535
What is the name of your pdf printer?
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

Author Comment

by:Ronald Malk
ID: 42136544
looks like  I'm stuck with your question, Do not know how to find out, but I can tell that I have installed in my computer Acrobat reader DC I don't know if that helps?
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 42136551
Nope
0
 

Author Comment

by:Ronald Malk
ID: 42136558
For some reason it's not listed it the devices list, I'll do some googling hopefully find why not there, but for now it seems that I have to wait till I find out the name of the PDf printer in my PC
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 42136559
You will probably have to install it (it will be a separate software)
0
 

Author Comment

by:Ronald Malk
ID: 42136564
I installed one called PDFCreator under propery comment it says "eDoc Printer"
0
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 42136582
then try
Private Sub BtnPdf_Click()
Dim FileName As String
Dim FilePath As String
Dim inStkN As Integer
strPrinter = "eDoc Printer"
Dim frm As Form
Set frm = Screen.ActiveForm
Dim strPrinter As String
strPrinterPDF = "eDoc Printer"
inStkN = Me.StkN
FileName = "Transf-" & inStkN
FilePath = "C:\Users\orly\Desktop\FolderName\"
Set Application.Printer = Application.Printers(strPrinterPDF)
DoCmd.OpenReport "Msg_FrmC", acViewPreview, , "StkID = " & frm.StkID
DoCmd.PrintOut acPages, 1, 1
DoCmd.Close acReport, "Msg_FrmC"
Set Application.Printer = Nothing
End Sub

Open in new window

0
 

Author Comment

by:Ronald Malk
ID: 42136669
Please have a look at What I did ,, I'm having Error in this line
Set Application.Printer = Application.Printers(strPrinterPDF)

Dim FileName As String
Dim FilePath As String
Dim inStkN As Integer
Dim strPrinter As String
Dim strPrinterPDF As String
Dim frm As Form

strPrinter = "eDoc Printer"
Set frm = Screen.ActiveForm
strPrinterPDF = "eDoc Printer"
inStkN = Me.StkN
FileName = "Transf-" & inStkN
FilePath = "C:\Users\orly\Desktop\FolderName\"
Set Application.Printer = Application.Printers(strPrinterPDF)
DoCmd.OpenReport "Msg_FrmC", acViewPreview, , "StkID = " & frm.StkID
DoCmd.PrintOut acPages, 1, 1
DoCmd.Close acReport, "Msg_FrmC"
Set Application.Printer = Nothing
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 42136677
Which error?
0
 

Author Comment

by:Ronald Malk
ID: 42136682
in this line
 Set Application.Printer = Application.Printers(strPrinterPDF)
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 42136734
I mean the message
0
 
LVL 52

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 2000 total points
ID: 42136802
Is the Printer in the list created by the macro with which name
Sub PrinterList()

For Each prn In Application.Printers
    strRes = strRes & prn.DeviceName & vbCrLf
Next
MsgBox strRes, , "Printers"
End Sub

Open in new window

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 42137784
You did not state what data the first page contains, ...or why you only need to print the first page...?
Page 1=Header
Page 2 and over= Details

In any event, ...instead of going through all these machinations, ...why not simply create a report that only displays (or filters) the first page info?
Then all you have to do is create the PDF from that...
The other issue is that you seem to be outputting a "Form" to a PDF:
   DoCmd.OutputTo acOutputForm, "Msg_FrmC", acFormatPDF, FilePath & FileName & ".pdf", True
Try creating a "Report" and the output will look a lot better.
   DoCmd.OutputTo acOutputReport, "Msg_RptC", acFormatPDF, FilePath & FileName & ".pdf", True

JeffCoachman
0
 

Author Comment

by:Ronald Malk
ID: 42141901
Very Sorry for coming back so late,, Thank you for your passion, Finally it worked I reinstall the pdf creator and used your code with one change I replaced the Printers(strPrinterPDF) with Printers(o) and it works, that's it thank you again
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question