By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,659 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

How to switch back from report Print Preview to Report View via VBA ?

P: 23
Hello everybody.
I am developing database for my patients. I have almost the needed stuff but now struck at report level. At the end of all required data entry, I want to give prescription to my patients in printed form. For that I have made a report that opens in 'Report view' as a pop-up window. On that report, name it as 'rptOPDTreatment', I have put a command button 'cmdPreview' that I use to open report in 'Print Preview'. Now I want to go back to 'Report View', I have to right click on report border and select 'report View' to go back. Is there any vba code that I could place in 'OnClose' event that could reopen the report in 'Report View'..?
I have used following code in OnClose event

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Close()
  2. Dim HisttID, rptView As Integer
  3. HisttID = Me.HistoryID
  4. rptView = Report.CurrentView
  5. If (rptView = 5) Then
  6.  DoCmd.OpenReport "rptOPDTreatment", acViewReport, , "HistoryID = " & HisttID
  7. End If
  8. End Sub
But it gives run time error '2585' 'This action can not be carried out while processing a form or report event.

I have tried TempVars.Add method to fetch the CurrentView Integer in OnLoad event but that did not work either.
Please help me solve this issue.
Nov 28 '13 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 5K+
P: 5,397
I know that ACC2007/2010 have made reports interactive. IMHO: A very annoying and useless thing to do. You have; however, found out the hard way that reports really shouldn't be interactive at all in that once opened... how do you get back.

If you will tell me which version of ACC you are using I may be able to help; however, it's not a promising thing.
Nov 29 '13 #2

P: 23
Thank zmbd for response.
I am using MS ACCESS 2010. I get back by right clicking on report border and then selecting report view.
Nov 29 '13 #3

Expert Mod 5K+
P: 5,397
THis isn't pretty but it works.
Open the report in design view
show the properties for your report
Event tab
on close event

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  4. Private Sub Report_Close()
  5.     On Error Resume Next
  6.     DoCmd.RunCommand acCmdReportView
  7. End Sub
When you close out of the print preview it should take you back to the report view.
I hate the use of the resume next error trap; however, in this case it seems to be the only solution.

See if this works for you...

If I come across somethning better I'll update it here.

Nov 29 '13 #4

P: 23
Thanks zmbd
I have found another simpler way. That if you press 'c' while in 'Print Preview', it takes you to 'Report View'.
Anyways thanks very much for your concern.
Nov 29 '13 #5

Expert Mod 5K+
P: 5,397
Glad that works for you; however, that does not work for me in either of the test databases I've currently open.
Thus, there must be something else going on... curious!
Nov 29 '13 #6

Post your reply

Sign in to post your reply or Sign up for a free account.