Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access print preview command

Posted on 2013-12-18
9
Medium Priority
?
2,590 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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 …
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

670 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