Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Close all open reports

Posted on 2010-11-28
8
Medium Priority
?
467 Views
Last Modified: 2012-05-10
I have this code that I have adapted from a post i found on here.
I want to close all open reports in the current database

The code is in the Timer event of a hidden form (frmRprtTimer) that opens when any report opens.

Option Compare Database
Option Explicit

Private Sub Form_Timer()
On Error GoTo Err_Form_Timer
Dim rpt As Report
Dim db As Database
Dim cont As Container
    Set db = CurrentDb()
    Set cont = db.Containers("Reports")
    For Each rpt In cont
        DoCmd.Close
    Next rpt
    DoCmd.Close acForm, "frmRprtTimer"
Exit_Form_Timer:
    Exit Sub
Err_Form_Timer:
    MsgBox Err.Description
    Resume Exit_Form_Timer
End Sub

I keep getting an error.
Can anyone help?
0
Comment
Question by:Stephen Byrom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 34226192
when you close the report via docmd.close you have to specify the type and report name (like your timer)
eg

docmd.close acreport, rpt.name
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 1000 total points
ID: 34226203
try this alternative


Private Sub Form_Timer()
    CloseAllReports
    DoCmd.Close acForm, "frmRprtTimer"
End Sub

Private Sub CloseAllReports()

    Dim i As Integer
    Dim sName As String
    
    For i = 0 To CurrentDb.Containers("Reports").Documents.count - 1
        sName = CurrentDb.Containers("Reports").Documents(i).Name
        Debug.Print "Closing", sName
        DoCmd.Close acReport, sName
    Next i
    
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:Stephen Byrom
ID: 34226206
Tried that rocki.
I get
"Operation is not supported for this type of object"
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Closing Comment

by:Stephen Byrom
ID: 34226218
Your alternative code worked great.
Thanx for the help.
Much appreciated
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 34226227
no worries :)
0
 
LVL 1

Author Comment

by:Stephen Byrom
ID: 34226253
Getting answers and code from here has taught me a lot, and is much appreciated.
I have managed to build a decent Stock database with yours and other's help.
Is there a book or some other refernece that you would recommend that I could learn more about coding in VBA?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 34226318
I don't know of any books as my vba knowledge is all self taught. I did find one useful site for noobs though that you may find useful
http://functionx.com/vbaccess/index.htm
0
 
LVL 1

Author Comment

by:Stephen Byrom
ID: 34229359
Thanx Rocki.
Very usefull site.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

660 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