Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Jul 2002
    Location
    North Dakota, USA
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Preview a Report on a Form (2000)

    I would like to build a Report Viewer out of a form. I'd like to build a list of all/some reports in my database and then when I click on one, the report is displayed to the right. See the attached jpg for an example of the form. This list of reports is a listbox based on a table with one text field. The white box on the right is a subform. I'd like to click on a report name and then it's displayed in the subform on the right. Do you think something like this is possible? Is there another way to do this?

    Thanks.
    Sarah
    Attached Images Attached Images

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Preview a Report on a Form (2000)

    I don't think you can preview a report in a subform. Let's hope for you that one of the other Loungers proves me wrong. The way a report is formatted for display is very different from the way a form is laid out. Access provides a neat way to preview a report. It's called ... Preview mode.

    What you could do is create a form with just the list box displaying a list of reports; make the form a popup form, so that it will stay on top of all other windows.

    When the user clicks a report name, do the following in code:
    <UL><LI>Check if the report with the selected name is open (set On Error Resume Next to prevent an error from interrupting the code, then try to refer to the Page property of the report. If Err = 0 then, i.e. no error occurred, the report is open.)
    <LI>If so, activate it using DoCmd.SelectObject
    <LI>Otherwise, open it in preview mode. (If you wish, you can close all open reports first.)[/list]This is not exactly the same as what you want, but the effect is more or less the same. Opening a report on each click in the list box might be a bit much. You could react to a double click instead, and/or provide an OK button.

  3. #3
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Preview a Report on a Form (2000)

    The nearest thing I can suggest is to take a screen shot of your report, shrink it down and then display it in an image control. It would be a resource hog, a space hog and a PITA to do but... <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

  4. #4
    Lounger
    Join Date
    Jan 2003
    Location
    Herndon, Virginia, USA
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Preview a Report on a Form (2000)

    If you really had to do this, you might be able to do it using a couple step process (which would probably be slow).

    I believe the snapshot viewer can be used as an OCX control (and the only reason I think this is because snapshot files can be viewed in IE). So you could theoretically export the report to a snapshot file when you click on the report name, then view the snapshot file in the control to the right.

    I haven't tested this out, and it would certainly be slow, but it might work.

    Brent

  5. #5
    Lounger
    Join Date
    Jan 2003
    Location
    Herndon, Virginia, USA
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Preview a Report on a Form (2000)

    Hi, doing this using snapshots is actually easier and less painful than I thought. I've attached a sample Access 2000 database (using some of the Northwind reports) which demonstrates how to do it.

    I've created a form, which has the snapshot viewer control and a list of reports, and a table to contain information about the reports. The table has the following fields: Report Name (a text field that stores the access name of the report), Report Title (a text field that stores what the report should be called in the listbox), Snapshot File Name (a text field that stores the full name of the file to create, including path and extension), and Viewer? (a Yes/No field indicating whether or not you want to use this report in the viewer).

    You would need to populate the table with the names and information about the reports before using the viewer. I've included a query (Objects) which makes this easier, since it reads the MSysObjects table to give you a list of all the object names in the database. All you have to do is copy the report names to tblReports and then assign them titles, file names and check the Viewer? column.

    The form requires that the Snapshot Viewer be installed, because it uses the snapview.ocx file which is installed along with it. The viewer can be downloaded from http://office.microsoft.com/downloads/2000/Snpvw90.aspx .

    Here's the two lines of code needed to make it work:

    <pre>DoCmd.OutputTo acOutputReport, Me![lstReports], acFormatSNP, Me![lstReports].Column(2)
    Me![xSnapView].SnapshotPath = Me![lstReports].Column(2)
    </pre>



    Line 1 creates the snapshot file for the report. Line 2 sets the path for the snapshot viewer control to the file name created. lstReports is the list box with the report names, Column(2) of it has the file name from the table, and xSnapView is the snapshot viewer control.

    If I were actually going to use this, I would add in error handling, check to make sure that there's a file name for the report, etc.

    My initial expectation was that it would be a really slow process to create the snapshot file and then view it in the control. It isn't actually too bad. If the report is long, it can be slow, but generally it takes only a little bit longer than previewing the report.

    The only problem I've found is that the "printing page x of y to file z" box comes up when it creates the snapshot, which is annoying if you don't want the user to know that you're creating a file on their computer, but it does provide feedback that something is happening. Does anyone know of a way to keep this from happening? (I've tried setting Echo and SetWarnings to false and they didn't work).

    Brent
    Attached Files Attached Files

  6. #6
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Preview a Report on a Form (2000)

    Hi Brent

    Nice demo, exactly what I was looking for.

    John

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •