473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
  9.  
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.
Thanks
Nov 28 '13 #1
5 14263
zmbd
5,501 Expert Mod 4TB
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
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
zmbd
5,501 Expert Mod 4TB
Ok,
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
  3.  
  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.

-z
Nov 29 '13 #4
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
zmbd
5,501 Expert Mod 4TB
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

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

Similar topics

1
by: Devesh Aggarwal | last post by:
I developed reports in Crytsal Reports 9.0 in landscape mode. When i print the same from crystal reports it prints perfectly in Landscape even if the printer setting is set to potrait by default. ...
7
by: Pat | last post by:
I would like to send the Print Preview of a MS Access form to a Snapshot file. The form contains an OLE graph. BACKGROUND A snapshot of a report is possible. If I could I would use a report to...
1
by: sea | last post by:
I have Access 2002 and I am writing this application with a custom menu bar that has a print preview button -- the start up options hide the design window. The problem is that when an open form is...
2
by: Dean Slindee | last post by:
Anybody written code in VB.NET to: 1) show a print preview window of reports already written and stored in an Access 2002 database; or 2) execute the print of a report stored in an Access 2002...
2
by: Brad Pears | last post by:
I have a vb.net 2005 application and am using the print preview screen. This screen has a printer icon on it that the user can use to print the document currently being viewed. It uses the default...
4
n8kindt
by: n8kindt | last post by:
i have a thread posted elsewhere but it got long and messy. this is all that needs to be seen: http://i3.photobucket.com/albums/y72/n8kindt/verticalerror2-1.jpg the report looks great until i...
4
by: scubasteve | last post by:
I've developed a product pricing application for a client in AC2007. They enter all the data on the one main form, then click a button to open a printable report in Print Preview. My problem...
3
by: KingKen | last post by:
I would like to create an active hyperlink in my report that would allow me to open a form. Is there a way to accomplish this?
1
by: isaace | last post by:
I have an agreement template in a MS access report. The report's fields are populated by the form's records. my goal is to automate the report to filter to the agreement # to what ever the current...
5
by: jcrist30 | last post by:
I have a report with several fields/text boxes that are used to determine the values of various report/field totals. Everything is calculating and populating the fields correctly when I view the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.