Solved

Access print preview command

Posted on 2013-12-18
9
2,037 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:jrsitman
  • 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:jrsitman
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
 

Author Comment

by:jrsitman
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
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)

 

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:jrsitman
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:jrsitman
ID: 39728739
Thanks.  @mbizup, with all you have to do, how do you find time to also help here?  :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syntax Error in Query 7 31
MS Access Memo (Long Text) Field Not Exporting Correctly From a Query 13 42
Query design issue 2 24
Access coding 2 13
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

896 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now