Link to home
Start Free TrialLog in
Avatar of Jack Marley
Jack Marley

asked on

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

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!
ASKER CERTIFIED SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jack Marley
Jack Marley

ASKER

Great! Thanks again Phil.
You're welcome.