Link to home
Start Free TrialLog in
Avatar of mlcktmguy
mlcktmguyFlag for United States of America

asked on

Printing the report in print preview, using VBA code

In my Access 2013 app I am creating my own custom ribbon to show when any report in in print preview mode.  I don't want all of the options in the system 'Print Preview' ribbon.
I only want 'Quick Print' (directly to printer), Print With Options (Popup the Printer Dialog Box), Export To Word, Export To PDF and Close Print Preview

I have developed routines for all but 'Quick Print' and 'Print with Options'.    The export and Close options were coded generically so they aren't dependent on the version of MS Office or MS Access on the machine.  Here are the routines.

Public Function closeReport()

Dim rptName As String

rptName = Screen.ActiveReport.Name

DoCmd.Close acReport, rptName

End Function
Public Function printOutputToPDF()

printOutputTo (cFormatPDF)

End Function
Public Function printOutputToRTF()

printOutputTo (cFormatRTF)

End Function

Public Function printOutputTo(passedOutputFormat As String)


' "PDF"
' "RTF"
'
'Select Output Location
'

' GetObject Name
Dim rptName As String
Dim outputExtension As String
Dim outputLocation As String
Dim OutputNameAndLocation As String

outputExtension = "." & passedOutputFormat
'
rptName = Screen.ActiveReport.Name
'
outputLocation = BrowseFolder("Select folder where output will be placed")    ' CurrentProject.Path
'
If outputLocation = vbNullString Then
    MsgBox "No output folder was selected, no output will be created"
    Exit Function
End If
'
OutputNameAndLocation = outputLocation & "\" & rptName & outputExtension

If passedOutputFormat = cFormatPDF Then
    DoCmd.OutputTo acOutputReport, rptName, acFormatPDF, OutputNameAndLocation, True    'acformatpdf  acFormatRTF
    '
ElseIf passedOutputFormat = cFormatRTF Then
    DoCmd.OutputTo acOutputReport, rptName, acFormatRTF, OutputNameAndLocation, True     'acformatpdf  acFormatRTF
    '
End If
'
'MsgBox "Output FIle " & OutputNameAndLocation & " has been created."
'



End Function

Open in new window

If possible I want to both Print options to also be generic, not depending on the specific version of Office or Access on the machine.

I though the Print command would be easiest but I don't know the code to make the current report 'Screen.ActiveReport.Name' go directly to the printer or to popup the print dialog box.

Anyone know what the commands are for these two options.
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
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 mlcktmguy

ASKER

Thanks I didn't realize that would work when the report was already in preview mode.  That takes care of 'Quick Print'.

Do you know of any way to use code to pop-up the printer dialog box, allowing the user to re-direct the output or only print portions of the entire report.

I know I did this years ago on a VB project but have no recollection of how it was done?
Thanks once again for helping me out.