Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Apr 2003
    Location
    Vail, Colorado, USA
    Posts
    194
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Close all open reports (Access 2000)

    I am trying to close all reports that are open. The following is the last bit of code I tried
    Function ReportCross()
    Dim rpt As Report
    MsgBox Reports.Count
    For Each rpt In Reports
    rpt1 = rpt.Name
    DoCmd.Close acReport, rpt1
    Next rpt
    MsgBox Reports.Count
    End Function

    This always leaves some reports open. I have searched help and online for a solution and would appreciate anyone's suggestionws.

    Mitch

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

    Re: Close all open reports (Access 2000)

    In situations like these, you must always loop backwards, for looping forwards pulls the rug from under the code, as it were.

    Function ReportCross()
    Dim i As Long
    For i = Reports.Count - 1 To 0 Step -1
    DoCmd.Close acReport, Reports(i).Name
    Next i
    End Function

  3. #3
    2 Star Lounger
    Join Date
    Apr 2003
    Location
    Vail, Colorado, USA
    Posts
    194
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Re: Close all open reports (Access 2000)

    Thanks Hans that worked just fine. I had tried something similar by setting a loop based on the number of open reports then trying to close index 0 assuminmg that exisited until the last report but Access did not like it. Anyway thanks once again for a simple solution.

    Regards

    Mitch

Posting Permissions

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