none
runtime error 2450 when form is not loaded RRS feed

  • Question

  • i have form "form" i am using it for data entry

    I want to Requery another form so I use

    Private Sub Form_AfterInsert()
    [Forms]![form1]![Child15].Requery
     End Sub

    its work fine when form1 is open

    after close it I get error 2450

    any help please


    • Edited by qwertyess Thursday, December 10, 2015 2:42 PM
    Thursday, December 10, 2015 2:40 PM

Answers

  • If your other form is supposed to display information based on your new record in the current form, then the AfterInsert event is a poor choice for performing a requery of the other form.  The problem is that though you have inserted the record, you haven't actually committed it yet. 

    Furthermore, you can't perform actions on a form that is closed, so of course you're going to get an error.

    So first you need to consider a more appropriate event for executing your action.  Perhaps the Form.AfterUpdate or Form.Close events would be more desirable.

    Next, you need to test to ensure the other form is open before trying to execute your action.

    • Marked as answer by David_JunFeng Wednesday, December 23, 2015 2:35 PM
    Friday, December 11, 2015 7:54 AM

All replies

  • Try checking to see if Form1 is loaded first:

    If CurrentProject.AllForms("Form1").IsLoaded Then
      ' etc

    You may also want to add error handling to your Sub

    On Error goto PROC_ERR   

    ' Your Code goes here    

    Exit Sub

    PROC_ERR      

    If err.Number = 2450 then resume next  Else msgbox "Error " & Err.Number & ": " & Err.description

    End Sub



    Miriam Bizup Access MVP


    • Edited by mbizup MVP Thursday, December 10, 2015 2:47 PM
    Thursday, December 10, 2015 2:47 PM
  • >>>its work fine when form1 is open

    after close it I get error 2450<<<

    According to your description, there are not enough information to make us to reproduce your issue. could your provide more information about your issue, for example full sample code, screenshot etc., that will help us reproduce and resolve your issue.

    Thanks for your understanding

    Friday, December 11, 2015 4:25 AM
  • If your other form is supposed to display information based on your new record in the current form, then the AfterInsert event is a poor choice for performing a requery of the other form.  The problem is that though you have inserted the record, you haven't actually committed it yet. 

    Furthermore, you can't perform actions on a form that is closed, so of course you're going to get an error.

    So first you need to consider a more appropriate event for executing your action.  Perhaps the Form.AfterUpdate or Form.Close events would be more desirable.

    Next, you need to test to ensure the other form is open before trying to execute your action.

    • Marked as answer by David_JunFeng Wednesday, December 23, 2015 2:35 PM
    Friday, December 11, 2015 7:54 AM