Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Access print preview command

Posted on 2013-12-18
9
Medium Priority
?
2,721 Views
Last Modified: 2013-12-19
How do I change this code to get  print preview?

  On Error GoTo Err_cmdPetProfile_Click
   
    Dim stDocName As String
    If Me.Dirty = True Then
        Me.Dirty = False
    End If
   
    stDocName = "rptPetProfile_Cat"
    DoCmd.OpenReport stDocName, acViewPreview, wherecondition:="[SoftSlip] = '" & Me.SoftSlip & "'"
   
    DoCmd.PrintOut Copies:=1
0
Comment
Question by:J.R. Sitman
  • 4
  • 3
  • 2
9 Comments
 

Expert Comment

by:SimonRidd
ID: 39727800
you can use

DoCmd.RunCommand acCmdPrintPreview 

Open in new window


to display the print preview
0
 

Author Comment

by:J.R. Sitman
ID: 39727818
I got the attached error.

stDocName = "rptPetProfile_Cat"
    DoCmd.OpenReport stDocName, acCmdPrintPreview, wherecondition:="[SoftSlip] = '" & Me.SoftSlip & "'"
   
    DoCmd.PrintOut Copies:=1
    DoEvents
    DoCmd.Close acReport, "rptPetProfile_Cat"
   
Exit_cmdPetProfile_Click:
    Exit Sub
print-preview.png
0
 

Expert Comment

by:SimonRidd
ID: 39727835
Apologies for my previous (before edit) answer. I jumped the gun a little there. I said that acCmdPrintPreview wasn't a member of acView which is correct, but acViewPreview is which was in your original code.

I'm a little confused, and my original question in this answer now stands as being more valid - what exactly are you trying to achieve/is the problem? How are you telling that the code isn't opening in print preview? The code posted by you opens the report in print preview, prints a copy and then closes the report again.
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

Author Comment

by:J.R. Sitman
ID: 39727862
The reason is it's a new report and I need to preview it so I can capture a screen shot.  I added your code exactly as shown and still get the same error.
0
 

Expert Comment

by:SimonRidd
ID: 39727910
Stepping through your original code with F8, when you get to this line
DoCmd.OpenReport stDocName, acCmdPrintPreview, wherecondition:="[SoftSlip] = '" & Me.SoftSlip & "'"

Open in new window

do you get the result you desire? If not, what happens?
0
 

Author Comment

by:J.R. Sitman
ID: 39728016
When I push F8 nothing happens
0
 
LVL 61

Accepted Solution

by:
mbizup earned 1200 total points
ID: 39728360
Your original code should be opening the report in  print preview, as-is.

The problem is that you are closing the report immediately after printing the report.

If you want the report to remain open in Print Preview, try removing the Close statement and have the user close the report independently.  Also, the acViewPreview you had in the code originally should be fine.


stDocName = "rptPetProfile_Cat"
     '  Your original acViewPreview was correct.
    DoCmd.OpenReport stDocName, acViewPreview, wherecondition:="[SoftSlip] = '" & Me.SoftSlip & "'"
    
    DoCmd.PrintOut Copies:=1
    DoEvents
  '   DoCmd.Close acReport, "rptPetProfile_Cat"  *** Remove this line so that you are not closing the report immediately.
    
Exit_cmdPetProfile_Click:
    Exit Sub

Open in new window

0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 1200 total points
ID: 39728363
Also, if you JUST want print preview, remove the printout command as well.  That will simply bring the report up in print preview, and the users can print and close the report on their own terms:

stDocName = "rptPetProfile_Cat"
     '  Your original acViewPreview was correct.
    DoCmd.OpenReport stDocName, acViewPreview, wherecondition:="[SoftSlip] = '" & Me.SoftSlip & "'"

   ' *** remove everything past this point, and just bring the report up in print preview
   ' DoCmd.PrintOut Copies:=1
  '  DoEvents
  '   DoCmd.Close acReport, "rptPetProfile_Cat"  *** Remove this line so that you are not closing the report immediately.
   
Exit_cmdPetProfile_Click:
    Exit Sub
0
 

Author Closing Comment

by:J.R. Sitman
ID: 39728739
Thanks.  @mbizup, with all you have to do, how do you find time to also help here?  :-)
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

885 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