Solved

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

Posted on 2016-10-06
3
39 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
  • 2
3 Comments
 
LVL 34

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 34

Expert Comment

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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In case Office 2010 has not been deployed in your environment, this article may be quite useful. In our office, we wanted a way to deploy Microsoft Office Professional Plus 2010 through an automated batch file via logon script. This article is docum…
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now