Solved

Access print preview command

Posted on 2013-12-18
9
1,987 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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…

707 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

17 Experts available now in Live!

Get 1:1 Help Now