Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-access > #10792

Re: Form_formname method stopped working!

From Ulrich Möller <knobbi38@arcor.de>
Newsgroups comp.databases.ms-access
Subject Re: Form_formname method stopped working!
Date 2015-06-04 17:52 +0200
Organization A noiseless patient Spider
Message-ID <mkps59$4tu$1@dont-email.me> (permalink)
References <mknnv8$vfp$1@dont-email.me> <mkp945$s8g$1@dont-email.me> <4b6b6032-1811-4857-a436-6ed10b0dc227@googlegroups.com>

Show all headers | View raw


Am 04.06.2015 um 14:01 schrieb Neil:
> On Thursday, June 4, 2015 at 5:27:33 AM UTC-5, Ulrich Möller wrote:
>> Am 03.06.2015 um 22:28 schrieb Neil:
>>> I have a database that uses a tab control in its main form. Each form
>>> is a subform on a tab of the tab control, and some of those forms have
>>> subforms of their own.
>>>
>>> When I want to get a value in one of the subform's subforms, rather
>>> than using the Forms!form... method three levels deep, I simply use
>>> the Form_formname method in my VBA code module.
>>>
>>> This has worked well. The database has been in development for several
>>> months, and in all testing there were no problems.
>>>
>>> Now today, all of a sudden, it stopped working. When I do, say:
>>>
>>>      somevariable = Form_MyFormName!ID
>>>
>>> the value is returned it completely wrong. Plus, it doesn't matter
>>> which record it's in; it always returns the same wrong value.
>>>
>>> Same goes for other subforms whose values I'm getting this way.
>>>
>>> I determined that what it's doing is returning values from the subform
>>> as though the subform were opened on its own, not as a subform and
>>> linked to the parent form and filtered for the parent form records.
>>> It's like the code is just opening a copy of the subform in the
>>> background and just returning the first record.
>>>
>>> This is very bizarre. Not only have I used the Form_formname method to
>>> get values for a very long time, but in this database itself it has
>>> been in place for a while, and has worked fine. Now all of a sudden it
>>> stopped working. What happened??
>>>
>>> Any input would be GREATLY appreciated!
>>>
>>> Thanks!
>> Hi Neil,
>>
>> the syntax Form_MyFormName is a reference to the class module of a form.
>> It represents the default instance and when the class is not already
>> instantiated, the form will be opened in hidden mode automatically.
>> This mechanism can be used for example when you want to call a public
>> method in that class module but i think it is not very usefull. By the
>> way, this opened form is not stored as reference in the forms collection
>> so you can not use the forms("myformname").isloaded syntax for
>> determining if the form is loaded or not. Indeed you must use the
>> classic syntax for referencing a control on a subform like
>> Forms![FormName]![SubformControName] because the default instance and
>> the instance referenced in a subform.form property are not identical and
>> each has its own local storage.
>>
>> Ulrich
> Ulrich,
>
> Thanks for your note. A couple of points.
>
> 1) In this case, wouldn't the form already be "instantiated," since it is open as a subform?
>
> 2) As noted in my original post, the code using Form_Formname to get a value from the subform has worked perfectly for months. Now, all of a sudden it's not working. Cannot understand why. But using Form_formname to get the subform value was fine up until yesterday.
>
> 3) The problematic subforms are two levels deep. That is, there is the main form containing the tab control. There is the first level of subforms, each on its own tab. And there are the subform subforms, which are the ones that are giving me problems. The syntax Form_formname is still working fine for the first-level subforms, directly under the tab control. It is only for the second-level subforms that it out-of-the-blue stopped working yesterday. But the same syntax is used for both levels of subforms. And, according to your logic, that you can't reference a subform using Form_formname, that should apply to the first-level subforms as well, no? But it doesn't.
>
> 4) It's as though the application, somehow, is not "seeing" the second-level subforms when I use Form_formname, and, thus, is opening a hidden instance in the background, as you state. But it was "seeing" them before yesterday.
>
> 5) More weirdness. The code is actually called from a button within a first-level subform's code module. So I tried changing the reference from Form_formname!ID to Me!subformname.form!ID. This worked yesterday. But today it's not working either. So even the standard  Form!Formname syntax isn't working now!
>
> 6) More weirdness. Yesterday the value that was always being returned, as noted, as the value from the first record in the subform if the subform was opened on its own, without filtering for the parent form's record. Today, though, it's returning the LAST record in the form!
>
> In my opinion, there seems to be some corruption that has caused this. But when multiple decompiles don't do the job, what do you do?
>
> Thanks,
>
> Neil
Hi Neil,

you can play around and make it clearer for you, if you put debug.print 
commands in the form/subform form open events and show the hwnd of the 
forms just opened. So you will be able to see, which instances you have 
and when they are created.
Referencing the form's class with the Form_formname syntax can work for 
you, but what form will be referenced when you have the same form used 
twice in different subform controls at the same time? From my point of 
view i decided to handle the default instance as a kind of static class 
in vba and that works for me quite well.

The problem with sometimes it works and after a few changes it won't 
work any more is still a problem in access vba. I have had similar 
problems when i used classes and interfaces. At one point, vba did not 
accept my public constants any more. I exported all as text and imported 
it again and i worked as expected. No idea why.

Ulrich

Back to comp.databases.ms-access | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Form_formname method stopped working! Neil <xxx@gmail.com> - 2015-06-03 15:28 -0500
  Re: Form_formname method stopped working! Larry Linson <larry.linson@verizon.net> - 2015-06-03 20:52 -0500
    Re: Form_formname method stopped working! Neil <nrgins@gmail.com> - 2015-06-04 05:10 -0700
  Re: Form_formname method stopped working! Ulrich Möller <knobbi38@arcor.de> - 2015-06-04 12:27 +0200
    Re: Form_formname method stopped working! Neil <nrgins@gmail.com> - 2015-06-04 05:01 -0700
      Re: Form_formname method stopped working! Ulrich Möller <knobbi38@arcor.de> - 2015-06-04 17:52 +0200
        Re: Form_formname method stopped working! Neil <xxx@gmail.com> - 2015-06-04 16:47 -0500
    Re: Form_formname method stopped working! Neil <nrgins@gmail.com> - 2015-06-04 05:40 -0700
  Re: Form_formname method stopped working! Neil <xxx@gmail.com> - 2015-06-04 09:32 -0500
    Re: Form_formname method stopped working! Larry Linson <larry.linson@verizon.net> - 2015-06-04 16:41 -0500
      Re: Form_formname method stopped working! Neil <xxx@gmail.com> - 2015-06-05 12:34 -0500
        Re: Form_formname method stopped working! Larry Linson <larry.linson@verizon.net> - 2015-06-05 23:01 -0500

csiph-web