none
Run-time error "2450" Application cannot find form - But the form is open

    Question

  • Hello,

    I do not understand why I am getting the run-time error "2450", when the form is open. The code the is bold is getting the error.  Your expert advise is truly appreciated:

     

    If CurrentProject.AllForms("frmclientmailschedule").IsLoaded Then
         If Forms!frmClientMailSchedule!ScheduleID <> " " Then
             Call openFormInstance("frmClientMailSchedule",   Forms!frmClientMailSchedule!ScheduleID, "Main")
           Else
               DoCmd.OpenForm "frmclientmailschedule", , , , acNew
              'IntMoveWindow = IntMoveWindow + 1
              'DoCmd.MoveSize (IntMoveWindow + 1) * 80, (IntMoveWindow + 1) * 350
        End If
     Else"
           DoCmd.OpenForm "frmclientmailschedule", , , , acNew
           'IntMoveWindow = IntMoveWindow + 1
           'DoCmd.MoveSize (IntMoveWindow + 1) * 80, (IntMoveWindow + 1) * 350
    End If 
    
    

     

    Thursday, October 13, 2011 2:05 PM

Answers

  • Hello,

    I do not understand why I am getting the run-time error "2450", when the form is open. The code the is bold is getting the error.  Your expert advise is truly appreciated:

     

    If CurrentProject.AllForms("frmclientmailschedule").IsLoaded Then
         If Forms!frmClientMailSchedule!ScheduleID <> " " Then
             Call openFormInstance("frmClientMailSchedule",   Forms!frmClientMailSchedule!ScheduleID, "Main")
           Else
               DoCmd.OpenForm "frmclientmailschedule", , , , acNew
              'IntMoveWindow = IntMoveWindow + 1
              'DoCmd.MoveSize (IntMoveWindow + 1) * 80, (IntMoveWindow + 1) * 350
        End If
     Else"
           DoCmd.OpenForm "frmclientmailschedule", , , , acNew
           'IntMoveWindow = IntMoveWindow + 1
           'DoCmd.MoveSize (IntMoveWindow + 1) * 80, (IntMoveWindow + 1) * 350
    End If 
    

     

    I notice that in one line you call a procedure "openFormInstance".  Does that procedure open a non-default instance of the form -- that is, one that is created by using some such statement as "Set frm = New Form_frmClientMailSchedule"?  In such a case the form is opened, but not indexed by name in the Forms collection.  The expression CurrentProject.AllForms("frmclientmailschedule").IsLoaded will return True, but an expression that indexes the Forms collection by name, such as Forms!frmClientMailSchedule, will not find the form.

    My guess is that the form is only open as a non-default instance, and that's why it can't be found.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html
    • Marked as answer by Bruce Song Monday, October 24, 2011 1:12 PM
    Thursday, October 13, 2011 7:33 PM

All replies

  • Try to change the line into:

    If IsNull(Forms!frmClientMailSchedule!ScheduleID) = False Then
    
    

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Thursday, October 13, 2011 2:21 PM
  • Thanks for your help.  I have tried all coding avenues, but still the same error. 

    Any more suggestions as to why I am getting this error even though the form is open is truly appreciated.

     

     

    Thursday, October 13, 2011 2:46 PM
  • If you do a simple test to see what message pops-up for you:

    If CurrentProject.AllForms("frmclientmailschedule").IsLoaded Then
         If IsNull(Forms!frmclientmailschedule!ScheduleID) = False Then
              MsgBox "Record is not empty"
           Else
              MsgBox "Record is empty"
        End If
    Else
    MsgBox "Form is not loaded!"
    
    End If 
    
    

    Let me know the results. Thanks!

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Thursday, October 13, 2011 3:51 PM
  • Thanks Daniel for your help,

    Followed your suggestion, what happens is the form can not be found, even though an instance of the form is open.  It is failing on the line of code that is bold.

    f CurrentProject.AllForms("frmclientmailschedule").IsLoaded Then
    If IsNull(Forms!frmclientmailschedule!ScheduleID) = False Then
    MsgBox "Record is not empty"
    Else
    MsgBox "Record is empty"
    End If
    Else
    MsgBox "Form is not loaded!"

    End If

    It can not find the form "frmClientMailSchedule".  A instance of the form is open, when trying to open another instance of the form I get the run-time error "2450".  I tried recoding that line of code different ways,  and get the same error.  Is it something I am missing or overlooking?  I am at a lost!!!

     

    Thursday, October 13, 2011 4:16 PM
  • I can't reproduce your error, even if it not exists or is closed.

    Even when the Control can't be find, is a different error.

     

    You can do a simple test, to if the Form is loaded indeed:

     

    If CurrentProject.AllForms("frmclientmailschedule").IsLoaded Then
    
    MsgBox "Form is loaded!"
       Else
    MsgBox "Form is not loaded!"
    
    End If 
    
    
    

     

    Your Form might be corrupt, I hope not, but the symptoms are not very hopeful.

    You can run a Compact & Repair, to see if that helps.

     

    Try with a different Form, and see if the error not pops-up.

     

    Hope this helps,

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Thursday, October 13, 2011 4:37 PM
  • I noticed in your original post you used capital letters to begin each word in bold but not in your 1st IF statement. Verify your name is correct including caps.
    Chris Ward
    Thursday, October 13, 2011 6:10 PM
  • Hello smsemail,

    I've had a similar problem with forms that have subform.  It turns out that Access cannot directly access subforms from within the parent form directly, you have to reference the subform object in the main form, not the subform itself.  Even though it's loaded, the main form cannot see it.  You have to do something similar to this:

    '(in the main form)
    me.SubformControl.Form![FieldName]

    If you try to access the subform by means of "Forms![frmSubform]![FieldName]" in the parent form it will tell you that it can't see the form.

    I hope that is the case, but I'm not sure.  I hope I helped  :)

    Zac

     


    Zac Ortiz
    Thursday, October 13, 2011 7:11 PM
  • Hello,

    I do not understand why I am getting the run-time error "2450", when the form is open. The code the is bold is getting the error.  Your expert advise is truly appreciated:

     

    If CurrentProject.AllForms("frmclientmailschedule").IsLoaded Then
         If Forms!frmClientMailSchedule!ScheduleID <> " " Then
             Call openFormInstance("frmClientMailSchedule",   Forms!frmClientMailSchedule!ScheduleID, "Main")
           Else
               DoCmd.OpenForm "frmclientmailschedule", , , , acNew
              'IntMoveWindow = IntMoveWindow + 1
              'DoCmd.MoveSize (IntMoveWindow + 1) * 80, (IntMoveWindow + 1) * 350
        End If
     Else"
           DoCmd.OpenForm "frmclientmailschedule", , , , acNew
           'IntMoveWindow = IntMoveWindow + 1
           'DoCmd.MoveSize (IntMoveWindow + 1) * 80, (IntMoveWindow + 1) * 350
    End If 
    

     

    I notice that in one line you call a procedure "openFormInstance".  Does that procedure open a non-default instance of the form -- that is, one that is created by using some such statement as "Set frm = New Form_frmClientMailSchedule"?  In such a case the form is opened, but not indexed by name in the Forms collection.  The expression CurrentProject.AllForms("frmclientmailschedule").IsLoaded will return True, but an expression that indexes the Forms collection by name, such as Forms!frmClientMailSchedule, will not find the form.

    My guess is that the form is only open as a non-default instance, and that's why it can't be found.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html
    • Marked as answer by Bruce Song Monday, October 24, 2011 1:12 PM
    Thursday, October 13, 2011 7:33 PM
  • This may be answered, but it is not explained.  Why is a non-default instance not referenced by its name?  It returns a name when queried.  Why does that name not in turn allow access to the instance?

    dim f as new form_custom
    debug.print CurrentProject.AllForms("custom").IsLoaded 'returns true
    debug.print Application.Forms.Count 'returns 1
    debug.print Application.Forms(0).Name 'returns 'custom'
    debug.print Application.Forms("custom").Visible 'throws runtime error 2450

    So why is this?  Is this another one of those frustrating foibles of Microsoft Development software?  Or is it an ongoing Microsoft bug no one is bothering to fix?

    I am using VBA module under Access 2010, and am trying to find a reliable way of recognizing when a form is available for manipulation by code.

    Thanks


    Phil.


    • Edited by PJMayo Thursday, May 15, 2014 2:15 PM
    Thursday, May 15, 2014 2:14 PM
  • This may be answered, but it is not explained.  Why is a non-default instance not referenced by its name?  It returns a name when queried.  Why does that name not in turn allow access to the instance?

    dim f as new form_custom
    debug.print CurrentProject.AllForms("custom").IsLoaded 'returns true
    debug.print Application.Forms.Count 'returns 1
    debug.print Application.Forms(0).Name 'returns 'custom'
    debug.print Application.Forms("custom").Visible 'throws runtime error 2450

    So why is this?  Is this another one of those frustrating foibles of Microsoft Development software?  Or is it an ongoing Microsoft bug no one is bothering to fix?

    I don't speak for Microsoft, but I'd say it's by design, and not a bug.  Consider: only one item in a collection can have any given index value. But you can have any number of non-default instances of a form open at once.  Which one of those instances should be indexed by its name?  What happens to the index if that form is then closed?  Does it somehow magically point to another instance?  Suppose you also open a default instance of the form?  Which instance should be indexed by name now?

    The issue raises lots of questions, with no good answers.  The simplest and clearest resolution is just to say, "Only form objects opened by the OpenForm action or method will be indexed by name."

    I am using VBA module under Access 2010, and am trying to find a reliable way of recognizing when a form is available for manipulation by code.

    The only reason for using non-default instances of forms is so you can have multiple instances open at once.  If you are using non-default instances, you must have your own mechanism for managing them, so I would recommend that you build a method to determine the status of the form into that mechanism.  If you are not using non-default instances, then open them with OpenForm; then their names will be in the Forms collection.

    If you are writing an add-in or utility routine that has no control or knowledge of whether a form is loaded non-default or not, then if you need to know whether any instance of a form is loaded, I don't see any better mechanism than iterating through the Forms collection:

    Function IsFormInstanceLoaded(FormName As String) As Boolean
    
        Dim frm As Access.Forms
    
        For Each frm In Application.Forms
            If frm.Name = FormName Then
                IsFormInstanceLoaded = True
                Exit Function
            End If
        Next frm
    
    End Function


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Thursday, May 15, 2014 2:37 PM
  • I got the same error, and others like it – all saying it couldn’t find an open form.  I was constructing a tax modeling database to compare various possible combinations of capital gains, IRA distributions, Social Security payouts, etc.  So my code had several forms open, including a 1040, a Schedule D, and tax form worksheets.  All the fields on all these forms were calculated from fields on the other forms, and back and forth.

    After much experimentation I think I know how VBA works with forms.  I think that VBA throws all the fields from all the open forms into one big bucket.  It can find any field (as it is on a current form record), but it doesn't see separate forms (except for the form with the last field referenced).  So you can't do "CurrentRecord", etc. with more than one form open.

    To get around this problem I embedded an unbound field on my main menu form called “PASS”, and then I kept opening each form (even if it was already open) and acGoTo that [PASS] record.

    Saturday, June 25, 2016 9:45 PM
  • Hi. I had the same problem when I closed the main form.  I discovered that I left another form open and Hidden, so when the main form was closed, the hidden one called another form that was already closed.
    Monday, November 07, 2016 7:43 PM
  • I've used code snippets from here but I'm still getting the  run-time error "2450".
    Friday, April 07, 2017 1:34 PM
  • First, try the following code in a Public Function to see if you get any errors when any form or forms are open:

    Public Function AllOpenForms()

    Dim obj As AccessObject
    Dim dbs As Object
    Set dbs = Application.CurrentProject
    For Each obj In dbs.AllForms
        If obj.IsLoaded = True Then
            DoCmd.SelectObject acForm, obj.Name
            MsgBox (obj.Name)
        End If
    Next obj

    Exit Function

    It should give you name of any and all open forms. If you re still getting an error when the code loops through all open forms, please state in text exactly what the error is saying, not just the error code number if possible.

    Friday, April 07, 2017 2:41 PM
  • To address this issue, we'd need more information about what you're doing, exactly what code you are using, and what line of code raises the error.

    In the original case in this thread, we were dealing with a non-default instance of the form.  Is that your case, too?  Is the form instantiated via the New keyword, or via DoCmd.OpenForm?


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Friday, April 07, 2017 3:44 PM
  • When a user logs in, I want to pass on the user id to a (hidden) label on the menu so that I may arrange the menu items accordingly.

    The first line in this code says the form I named "Menu" does not exits.

    Set frm = Forms!Menu 'or
                'Set frm = Forms("Menu")
                If Not frm Is Nothing Then
                  Set ctl = frm.Form!lblHoldPERSALNum
                  If Not ctl Is Nothing Then
                    ctl.Caption = nrPERSAL
                  Else
                    MsgBox "huh?"
                  End If
                Else
                  MsgBox "huh!"
                End If

                Set ctl = Nothing
                Set frm = Nothing

            
    Monday, April 10, 2017 1:37 PM
  • Are you saying that, when the code raises the error, you can look at the screen and see that the form in question is open?  If so, please check the actual name of the form.  The most likely reasons for this error are : (1) the form isn't open, or (2) the form isnt actually named "Menu".

    There are other possibilities, but they are far less common.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    • Proposed as answer by MarcusKgosi Wednesday, April 12, 2017 1:55 PM
    Monday, April 10, 2017 5:03 PM
  • The form is not open.
    Tuesday, April 11, 2017 7:04 AM
  • The form is not open.

    Then of course an error will be raised if you try to make a reference to it, such as the code line you posted:

        Set frm = Forms!Menu

    If you wanted, you could trap and respond to that error, but the simplest thing to do is test beforehand whether the form is open or not:

        If CurrentProject.AllForms("Menu").IsLoaded Then
            Set frm = Forms!Menu
            ' ... remainder of code referencing controls on frm ...
        Else
            ' ... do whatever should be done if the form isn't open ...
        End If


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Tuesday, April 11, 2017 3:08 PM
  • The error was resolved. My question now is how do I keep the Menu form open while logging in?
    Friday, April 21, 2017 7:22 AM
  • The error was resolved. My question now is how do I keep the Menu form open while logging in?

    This really ought to be a new thread, since it has nothng to do with the original question that started this thread.  But you haven't given enough information to address the question, anyway.  Logging in to what?  Why would the menu form not be open, if it was opened in the first place?  What closes it?

    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Tuesday, April 25, 2017 8:38 PM
  • Sorry Dirk, and I managed to keep the Menu form open.
    Wednesday, April 26, 2017 5:51 AM