Need to preview an Access report instead of print it

J.R. Sitman
J.R. Sitman used Ask the Experts™
on
What do I change in this code to preview the report instead of print it?

Private Sub cmdPetProfile_Click()
' Comments  :
    ' Parameters:  -
    ' Modified  : 01/29/02
    '
    ' --------------------------------------------------
    On Error GoTo Err_cmdPetProfile_Click
   
    Dim stDocName As String
    If Me.Dirty = True Then
        Me.Dirty = False
    End If
   
    stDocName = "rptPetProfile"
    DoCmd.OpenReport stDocName, acViewPreview, WhereCondition:="[SoftSlip] = '" & Me.SoftSlip & "'"
   
    DoCmd.PrintOut Copies:=1
    DoEvents
    DoCmd.Close acReport, "rptPetProfile"
   
Exit_cmdPetProfile_Click:
    Exit Sub
   
Err_cmdPetProfile_Click:
    MsgBox Err.Description
    Resume Exit_cmdPetProfile_Click
   
End Sub
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
comment this line


    DoCmd.PrintOut Copies:=1

like this

    ' DoCmd.PrintOut Copies:=1
Most Valuable Expert 2012
Top Expert 2013
Commented:
Your code IS previewing the report, as well as printing it.  The however, your code is also closing the report immediately thereafter (so the preview may be flashing up briefly or not seeming to appear at all).   See the inline comments:


    On Error GoTo Err_cmdPetProfile_Click
   
    Dim stDocName As String
    If Me.Dirty = True Then
        Me.Dirty = False
    End If
   
    stDocName = "rptPetProfile"

    ' This line does what you want - opens the report in print preview

    DoCmd.OpenReport stDocName, acViewPreview, WhereCondition:="[SoftSlip] = '" & Me.SoftSlip & "'"
   
    '*** Comment this next line out if you do not want a hard copy.

    DoCmd.PrintOut Copies:=1
    DoEvents


    '****** Comment this line out so that the preview stays open (visible)

    ' DoCmd.Close acReport, "rptPetProfile"
   
Exit_cmdPetProfile_Click:
    Exit Sub
   
Err_cmdPetProfile_Click:
    MsgBox Err.Description
    Resume Exit_cmdPetProfile_Click
   
End Sub
J.R. SitmanIT Director

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial