Solved

MS Access Form - Report from selected records and send to printer

Posted on 2016-10-06
3
102 Views
Last Modified: 2016-10-07
Hi,
I have a piece of VBA code written for me which outputs selected records as pdf reports.

Is it possible to amend the code so that instead of exporting as a PDF, it will print through the default printer?

All my attempts so far just print the active object ie the form itself.
Here's what I currently have:

Private Sub Command28_Click()
DoCmd.RunCommand acCmdSaveRecord
Forms!InvoiceNoEmail.SetFocus
Dim oApp As Object
Dim oEmail As Outlook.MailItem
Dim fileName As String
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("SELECT [Account], [InvoiceNum], [EmailAddress], [Company], [Printed] FROM [ContactTotalsNoEmail] WHERE (((Contracts.SelectedPrint)=True)) ORDER BY [Account];", dbOpenDynaset)

Do While Not rst.EOF
    strRptFilter = "[InvoiceNum] = " & Chr(34) & rst![InvoiceNum] & Chr(34)
    DoCmd.PrintOut
    fileName = "C:\Scripts\NoEmail" & "\" & rst![Account] & " - " & rst![InvoiceNum] & ".pdf"
    
    DoCmd.OutputTo acOutputReport, "InvTotalNoEmail", acFormatPDF, fileName
    rst.Edit
    rst![Printed] = "Yes"
    rst.Update
     DoEvents
     rst.MoveNext
   Loop
rst.Close
Set rst = Nothing
Forms!InvoiceNoEmail.Requery
End Sub

Open in new window


Any help would be greatly appreciated.
Thanks!
0
Comment
Question by:Jack Marley
[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
  • 2
3 Comments
 
LVL 37

Accepted Solution

by:
PatHartman earned 500 total points
ID: 41832265
Instead of or in addition to

DoCmd.OutputTo acOutputReport, "InvTotalNoEmail", acFormatPDF, fileName

Use

DoCmd.OpenReport "InvTotalNoEmail", acViewNormal

To preview a report use the acViewPreview argument instead.
1
 

Author Closing Comment

by:Jack Marley
ID: 41833212
Great! Thanks again Phil.
0
 
LVL 37

Expert Comment

by:PatHartman
ID: 41833829
You're welcome.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
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…

728 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