Solved

Access print preview command

Posted on 2013-12-18
9
2,085 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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 300 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 300 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

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