Ronald Malk
asked on
MS Access vba Print PDF First page only
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\Fol derName\"
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
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\Fol
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
ASKER
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\Fol derName\"
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
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\Fol
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
What is the name of your pdf printer?
ASKER
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?
Nope
ASKER
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
You will probably have to install it (it will be a separate software)
ASKER
I installed one called PDFCreator under propery comment it says "eDoc Printer"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Please have a look at What I did ,, I'm having Error in this line
Set Application.Printer = Application.Printers(strPr interPDF)
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\Fol derName\"
Set Application.Printer = Application.Printers(strPr interPDF)
DoCmd.OpenReport "Msg_FrmC", acViewPreview, , "StkID = " & frm.StkID
DoCmd.PrintOut acPages, 1, 1
DoCmd.Close acReport, "Msg_FrmC"
Set Application.Printer = Nothing
Set Application.Printer = Application.Printers(strPr
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\Fol
Set Application.Printer = Application.Printers(strPr
DoCmd.OpenReport "Msg_FrmC", acViewPreview, , "StkID = " & frm.StkID
DoCmd.PrintOut acPages, 1, 1
DoCmd.Close acReport, "Msg_FrmC"
Set Application.Printer = Nothing
Which error?
ASKER
in this line
Set Application.Printer = Application.Printers(strPr interPDF)
Set Application.Printer = Application.Printers(strPr
I mean the message
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
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
One way would be to have a pdf printer and then use
Open in new window
Caveat:The report needs to be opened before printing
Regards