[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2016-10-06
3
Medium Priority
?
110 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 39

Accepted Solution

by:
PatHartman earned 2000 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 39

Expert Comment

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

650 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