?
Solved

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

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

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 38

Expert Comment

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

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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