Group:  Microsoft Access ยป microsoft.public.access.modulescoding
Thread: Losing handles to form and control objects in Access 2007 VBA modu

Losing handles to form and control objects in Access 2007 VBA modu
Clay_LMCO 12/17/2008 9:32:02 PM
I have a library of classes that I use to manipulate MS Access UI objects
(forms, subforms, controls, etc.). My code has been bullet proof for the
past several months in Access 2003. Now I am migrating to 2007 and
everything has broken.

What I am encountering is the error message "The expression you entered
refers to an object that is closed or doesn't exist" when I try to get or set
property values of controls within my subforms. This appears to be a problem
related to the subforms and not parent forms. Everything still works with
the parent forms - at least as far as I can tell.

I can drill down to the objects using the object names like this...
Set frm = Application.Forms("MyForm")
frm.RecordSource = newSQL
...
Set ctl = frm.Controls("MyControl")
temp = ctl.Value

However, I get an error when I do something like this...
Me.RecordSource = "newSQL" 'Causes the error
...
temp = Me!MyContol.Value 'Also causes the error

It is even more curious to me that for some event callbacks things work
consistently (such as the form Load event callback - everything works fine
every time). Yet for other event call backs, things consistently do not work
(such as with a CommandButton Click event callback).

Anyone with any ideas?
--
Clay Watson
Lockheed Martin Aeronautics Company
Ft. Worth, Texas
RE: Losing handles to form and control objects in Access 2007 VBA modu
Tore 12/17/2008 11:42:01 PM

Are you missing any libraries? Open your vba code eitor. Select "Tools" in
the menu bar, then "References". Do you see the word "Missing" for any
library? Does your vba code compile without any errors?

Regards

Tore
RE: Losing handles to form and control objects in Access 2007 VBA
Clay_LMCO 12/18/2008 12:11:01 AM
Code compiles fine. There are no missing references.

I also checked names of tables vs. forms (per MSDN article on this same
error). There are no conflicts there either.

Thanks.
--
Clay Watson
Lockheed Martin Aeronautics Company
Ft. Worth, Texas


"Tore" wrote:

[Quoted Text]
>
> Are you missing any libraries? Open your vba code eitor. Select "Tools" in
> the menu bar, then "References". Do you see the word "Missing" for any
> library? Does your vba code compile without any errors?
>
> Regards
>
> Tore
Re: Losing handles to form and control objects in Access 2007 VBA modu
"Albert D. Kallal" <PleaseNOOOsPAMmkallal[ at ]msn.com> 12/18/2008 2:01:45 AM
I not really sure what you changed.

I converted applications with 160 forms, and 30,000+ lines of code....

And, I worked on applications where they have over 250 forms and 100,000 +
lines of vba, and we had not one problem with the code when it was moved to
2007.

So, something along the way here is causing a problem...I just don't know
what.

I would suggest perhaps you create a blank new 2007 database, and then
import everything from the existing one.


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal[ at ]msn.com


RE: Losing handles to form and control objects in Access 2007 VBA
Tore 12/18/2008 8:41:00 AM
Here is just another idea to check out.

May be you have a timing (racing) problem? Access 2007 and 2003 may be
significantly different when it comes to timing. If you refer fo a form (or
subform) that is not yet opened I guess you may get error message like you
describe. On several occasions I have experienced problems when code on a
main form try to access objects on a subform or vice versa. If you try to
access the subform on the on open event of the main form it is a question
wether the subform has managed top open thoroughly before you call it.

A simple test could be to build a test button and click it to call your code
when you are sure everything is stable, i.e. after the on open events etc.

Regards

Tore
RE: Losing handles to form and control objects in Access 2007 VBA modu
Clay_LMCO 12/18/2008 3:14:06 PM
Thanks to all for the comments. I still don't have a fix yet, but I think I
will get there. I have embedded pointers to subforms within VB class objects
to encapsulate too libraries I use across numerous applications. It appears
that this is a bit unconventional in the MS Access world, but has resulted in
higher levels of reusable code, big savings in programming time, and even has
performance benefits.

I am sure that the problem I am having has to do with persistence of object
pointers within these classes and is tied specifically to subforms.
Everything still works great at the parent for level. Is anyone aware of a
change in Access 2007 that would result in loss of persistence for subforms?
--
Clay Watson
Lockheed Martin Aeronautics Company
Ft. Worth, Texas


"Clay_LMCO" wrote:

[Quoted Text]
> I have a library of classes that I use to manipulate MS Access UI objects
> (forms, subforms, controls, etc.). My code has been bullet proof for the
> past several months in Access 2003. Now I am migrating to 2007 and
> everything has broken.
>
> What I am encountering is the error message "The expression you entered
> refers to an object that is closed or doesn't exist" when I try to get or set
> property values of controls within my subforms. This appears to be a problem
> related to the subforms and not parent forms. Everything still works with
> the parent forms - at least as far as I can tell.
>
> I can drill down to the objects using the object names like this...
> Set frm = Application.Forms("MyForm")
> frm.RecordSource = newSQL
> ...
> Set ctl = frm.Controls("MyControl")
> temp = ctl.Value
>
> However, I get an error when I do something like this...
> Me.RecordSource = "newSQL" 'Causes the error
> ...
> temp = Me!MyContol.Value 'Also causes the error
>
> It is even more curious to me that for some event callbacks things work
> consistently (such as the form Load event callback - everything works fine
> every time). Yet for other event call backs, things consistently do not work
> (such as with a CommandButton Click event callback).
>
> Anyone with any ideas?
> --
> Clay Watson
> Lockheed Martin Aeronautics Company
> Ft. Worth, Texas
RE: Losing handles to form and control objects in Access 2007 VBA modu
Clay_LMCO 12/18/2008 8:36:00 PM
I believe I have found the problem! Apparently the new version of MS Access
is multithreaded in ways that it was not in previous versions. What is
happening is that I have "critical sections" in my code that are being called
by multiple threads and the local variables are getting clobbered.
ARRRRGH!!!!!

At least I know what is happening. Thanks again to all that tried to help.
--
Clay Watson
Lockheed Martin Aeronautics Company
Ft. Worth, Texas


"Clay_LMCO" wrote:

[Quoted Text]
> I have a library of classes that I use to manipulate MS Access UI objects
> (forms, subforms, controls, etc.). My code has been bullet proof for the
> past several months in Access 2003. Now I am migrating to 2007 and
> everything has broken.
>
> What I am encountering is the error message "The expression you entered
> refers to an object that is closed or doesn't exist" when I try to get or set
> property values of controls within my subforms. This appears to be a problem
> related to the subforms and not parent forms. Everything still works with
> the parent forms - at least as far as I can tell.
>
> I can drill down to the objects using the object names like this...
> Set frm = Application.Forms("MyForm")
> frm.RecordSource = newSQL
> ...
> Set ctl = frm.Controls("MyControl")
> temp = ctl.Value
>
> However, I get an error when I do something like this...
> Me.RecordSource = "newSQL" 'Causes the error
> ...
> temp = Me!MyContol.Value 'Also causes the error
>
> It is even more curious to me that for some event callbacks things work
> consistently (such as the form Load event callback - everything works fine
> every time). Yet for other event call backs, things consistently do not work
> (such as with a CommandButton Click event callback).
>
> Anyone with any ideas?
> --
> Clay Watson
> Lockheed Martin Aeronautics Company
> Ft. Worth, Texas
RE: Losing handles to form and control objects in Access 2007 VBA modu
Clay_LMCO 12/18/2008 8:39:00 PM
I believe I have found the problem! Apparently the new version of MS Access
is multithreaded in ways that it was not in previous versions. What is
happening is that I have "critical sections" in my code that are being called
by multiple threads and the local variables are getting clobbered.
ARRRRGH!!!!!

At least I know what is happening. Thanks again to all that tried to help.
--
Clay Watson
Lockheed Martin Aeronautics Company
Ft. Worth, Texas


"Clay_LMCO" wrote:

[Quoted Text]
> I have a library of classes that I use to manipulate MS Access UI objects
> (forms, subforms, controls, etc.). My code has been bullet proof for the
> past several months in Access 2003. Now I am migrating to 2007 and
> everything has broken.
>
> What I am encountering is the error message "The expression you entered
> refers to an object that is closed or doesn't exist" when I try to get or set
> property values of controls within my subforms. This appears to be a problem
> related to the subforms and not parent forms. Everything still works with
> the parent forms - at least as far as I can tell.
>
> I can drill down to the objects using the object names like this...
> Set frm = Application.Forms("MyForm")
> frm.RecordSource = newSQL
> ...
> Set ctl = frm.Controls("MyControl")
> temp = ctl.Value
>
> However, I get an error when I do something like this...
> Me.RecordSource = "newSQL" 'Causes the error
> ...
> temp = Me!MyContol.Value 'Also causes the error
>
> It is even more curious to me that for some event callbacks things work
> consistently (such as the form Load event callback - everything works fine
> every time). Yet for other event call backs, things consistently do not work
> (such as with a CommandButton Click event callback).
>
> Anyone with any ideas?
> --
> Clay Watson
> Lockheed Martin Aeronautics Company
> Ft. Worth, Texas

Home | Search | Terms | Imprint
Newsgroups Reader