none
Forms() err.number 2450 to err.number 2456 - Acess VBA error - lost form RRS feed

  • Question

  • Hi all

    in a application I made in access, sometimes and only in some users, shoots the error number 2450 "Microsoft Access can't find form 'xpto' referred to in a macro expression or Visual Basic code.

    After read pages and pages in the net, cyclically make searches about the subject and to try lots of things I resolve to user item number of Forms collection to overcome this.

    Namely this:

    "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."

    I read this in:

    https://social.msdn.microsoft.com/Forums/office/en-US/42985542-1fd5-421b-b8e9-679868a339b3/runtime-error-quot2450quot-application-cannot-find-form-but-the-form-is-open?forum=accessdev

    So instead of Forms("FormName") i wrote Forms(2) - I had find that in the routine that has the problem the form always has this item number.

    Now I have precisely in the some form, vba line and user the application shooting the error 2456 The number used to refer to the form is invalid.

    Additional when this happens I have more that one form open.

    Because this error just happens in some users and sometimes I'm tend to think that this is also a utilization of the workstation problem...

    I also have additional difficulties because I can't replicate the situation that the error occurs, and believe me I tried a lot...

    Has some experience a situation like this that can share hints or leads to solve this.

    Thanks


    Joao Simplicio Rodrigues

    Thursday, March 21, 2019 2:48 PM

All replies

  • You are getting the error because forms don't have a visible property, only the controls on the form have a visible property. It's not a bug. You are attempting to print a form property that doesn't exist.

    Thursday, March 21, 2019 3:40 PM
  • I thought I explained, in the thread you quoted from, why non-default instances of forms are not indexed by their names in the Forms collection. Is that explanation unclear?

    If you are not using non-default form instances, then you have a completely different problem, and you'll need to give more information to let us figure it out.

    Are you using the Form_<formname> syntax to refer to your forms?  If so, you could be using a non-default instance without realizing it.  If you make some reference to Form_<formname> before you explicitly open the form (via DoCmd.OpenForm or the OpenForm macro action), then you will automatically create a non-default instance of the form.  On the other hand, if you open the form first, and *then* make some reference to Form_<formname>, you will be referring to the default instance of the form that was opened previously.  So the sequence of the actions -- reference to Form_<formname>, then OpenForm vs. Openform, then reference to Form_<formname> -- makes a very big difference.

    This is one of the reasons I strongly recommend not using the Form_<formname> syntax.

    By the way, the Form object does have a .Visible property.


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

    Thursday, March 21, 2019 4:33 PM
  • You could also try:

    debug.print Application.Forms("custom").Properties.Visible

    Thursday, March 21, 2019 10:15 PM
  • You could also try:

    debug.print Application.Forms("custom").Properties.Visible

    That won't work, because it implies that "Visible" is a property of the form's Properties collection, when it's actually a member of the collection.  But this should work, if the form is open as a default instance:

        Debug.Print Application.Forms("custom").Properties("Visible")


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

    Thursday, March 21, 2019 10:24 PM
  • I open the form like this:

    DoCmd.OpenForm "KOMANDO", acNormal, , , acFormPropertySettings, acWindowNormal, "string_with_openagrs"

    When  the error occurs I have 3 forms, opened in the same way but one off them is hidden:

    Forms("FirstForm").Visible = false
    I'm trying to replicate the situation to find out what happens in the workstations when the error pop-ups.



    Joao Simplicio Rodrigues


    Friday, March 22, 2019 3:02 PM
  • In your code, do you use the "Form_<formname>" syntax to refer to your forms or controls on them? 

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

    Friday, March 22, 2019 8:12 PM
  • Dirk reply to the Form's index is correct.

    It's to say that, if you have more than 1 form being opened. Your Index property/value is very likely to change.

    So in your case, Index 0 might be reference to another Form Name the next time the code is run. The Index is not consistent through out the process. Different user will not have the same Index referred to the form name.

    Example:

    User 1 Index(0) = "Customer"

    User 2 Index(0) = "Visitor" 

    Tuesday, March 26, 2019 8:55 AM
  • Thank you all for reply.

    After expend hours (that i don't have) is tests and involve a few users, because it was not possible to me to replicate the situation in which the error happens...

    I finally was able to determine that Access is working properly...

    For a reason I'm still trying to determine in some machines and with a few users the form KOMANDO disappears

    This form is the second to be open, of 3 forms opened at the same time and one of them (the first to be open) is not visible, and the third is working properly.

    This form, for a reason I haven't yet find, is closed. Don't know why but I have to agree ... The program is the same for a few dozens of users and just   happens with 2 or 3 users.

    And the worse is that in those 3 users doesn't happens always...

    All the workstations has the same "image" of software (windows / Office and so one...)

    I have to conclude, as we here says, that the problem is between the chair and the keyboard... :(

    Again thank you all.

    João


    Joao Simplicio Rodrigues

    Thursday, April 4, 2019 2:13 PM