Results 1 to 9 of 9

Thread: Report problem

  1. #1
    Join Date
    Nov 2005
    Posts
    113

    Unanswered: Report problem

    Hi,

    I have a report with a little form that filters in the report. I need to take care of the error that arrives if the user closes the report while the filter form is open and he presses the filter button - Error 2451 (No report open)

    When the user close the report I also wish that the filter form is closed. Haven't been albe to do that yet. (I get error 2501)

  2. #2
    Join Date
    Apr 2007
    Location
    Auburn, Kansas, USA
    Posts
    37
    Just add an event procedure in the on close for the report of this

    DoCmd.Close acForm, "<name of Filter Form>"

    -Tony

  3. #3
    Join Date
    Nov 2005
    Posts
    113
    I get error 2558 because the form closes the report and the report closes the form.

  4. #4
    Join Date
    Apr 2007
    Location
    Auburn, Kansas, USA
    Posts
    37
    ok I see... my bad! Try useing an IF Statement and use the IsLoaded funcation to even check if the report or form is loaded. You can use it in both Event Procedures to make sure that the form is loaded before you try to close it or if the report is loaded before you close it.

    Check out this link for more information on how to use it.
    http://msdn2.microsoft.com/en-us/lib...ffice.10).aspx

    -Tony

  5. #5
    Join Date
    Nov 2005
    Posts
    113
    Sorry Tony, is too difficult. I don´t understand the code.

  6. #6
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    Julita, the DoCmd.Close statement does not produce an error if the object is already closed. So what is the message part of the error message you are getting?

    I should not matter if the report is trying to close the form, or the form is trying to close the report.

    Plus, closing the form from the report will close the form long before you try to close the report. At least that is what has happened to me in the past. So I no longer try to close the form from the report.

  7. #7
    Join Date
    Apr 2007
    Location
    Auburn, Kansas, USA
    Posts
    37
    Here is a way to make sure that the form is closed

    Code:
        Dim obj As AccessObject, dbs As Object
        Set dbs = Application.CurrentProject
    
        For Each obj In dbs.AllForms
            If obj.IsLoaded = True Then
                If obj.Name = "<Name Of Form>" Then
                    DoCmd.Close acForm, "<Name Of Form>"
                End If
            End If
        Next obj
    Where <Name Of Form> is the form you are wanting to make sure is closed. The same can be done with a report

    Code:
        Dim obj As AccessObject, dbs As Object
        Set dbs = Application.CurrentProject
    
        For Each obj In dbs.AllReports
            If obj.IsLoaded = True Then
                If obj.Name = "<Name Of Report>" Then
                    DoCmd.Close acForm, "<Name Of Report>"
                End If
            End If
        Next obj
    Where <Name Of Report> is the name of the report you want to close.

    Wow Microsoft's help files do have some handy things in them every once and a while. This will search though all open Forms or Reports looking for the specific form or report and then close it if its found.

    Thats the best way I know of to do this. Hope it helps! Vic, if you know of another way then thats cool also.

    -Tony

  8. #8
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    Yes, I do know of another way. Just close the report or form. It does NOT have to be open when the DoCmd.Close is issued! DoCmd.Close does NOT raise an error if the object is already closed. So, you don't have to be sure it is open before trying to close it. Just close it. No error messages!

  9. #9
    Join Date
    Apr 2007
    Location
    Auburn, Kansas, USA
    Posts
    37
    Thats cool. I have never had this error come up before. Thanks for your insight Vic.

    -Tony

Posting Permissions

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