473,327 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Global object instances get reset?

Hi all,

Currently, I'm working on an Access XP database app that uses two
global objects in its code. These two objects are instances of
"controller classes". For example, one of them manages the multiple
open instances of a form (some sort of 'window manager').

These global objects are created in a module "General", by defining
them with e.g.:

Dim VwMng As New KViewManager

Now there seems to be a bit of a problem with these global objects:
when I'm running the application, at random times Access crashes when
the code accesses these global objects. Apparently, the instances are
sometimes reset by Access --- even though I'm not working on the code
and haven't recompiled anything explicitly.

I also tried modifying the above code with...

Dim VwMng as KViewManager

....and then explicitly doing a "Set VwMng = New KViewManager" in the
AutoExec startup function. Same problem: completely at random, the
references seem to become invalid.

It seems that I've just taken Access too far, or made things overly
complicated or so... So now I'm working to rework the code, but this
global objects problem keeps popping up --- e.g. defining an instance
of the class Collection in a module results in the same problem:
sometimes the collection just vanishes into thin air, crashing Access.

Now I'm sure that there are people in here with a lot more experience
than I have :) Is there a workaround? Is it possible to reliably have
global objects? Or is it such a bad practice that I should be deeply
ashamed :) ?

Your help would be highly appreciated.. Thanks in advance!

Yours sincerely,
Onno Broekmans

Feb 4 '07 #1
24 3450
On Feb 4, 6:48 am, "onn...@gmail.com" <onn...@gmail.comwrote:
Hi all,

Currently, I'm working on an Access XP database app that uses two
global objects in its code. These two objects are instances of
"controller classes". For example, one of them manages the multiple
open instances of a form (some sort of 'window manager').

These global objects are created in a module "General", by defining
them with e.g.:

Dim VwMng As New KViewManager

Now there seems to be a bit of a problem with these global objects:
when I'm running the application, at random times Access crashes when
the code accesses these global objects. Apparently, the instances are
sometimes reset by Access --- even though I'm not working on the code
and haven't recompiled anything explicitly.

I also tried modifying the above code with...

Dim VwMng as KViewManager

...and then explicitly doing a "Set VwMng = New KViewManager" in the
AutoExec startup function. Same problem: completely at random, the
references seem to become invalid.

It seems that I've just taken Access too far, or made things overly
complicated or so... So now I'm working to rework the code, but this
global objects problem keeps popping up --- e.g. defining an instance
of the class Collection in a module results in the same problem:
sometimes the collection just vanishes into thin air, crashing Access.

Now I'm sure that there are people in here with a lot more experience
than I have :) Is there a workaround? Is it possible to reliably have
global objects? Or is it such a bad practice that I should be deeply
ashamed :) ?

Your help would be highly appreciated.. Thanks in advance!

Yours sincerely,

Onno Broekmans
The only times I've encountered this is when there is insufficent
error handling.
Any time you get the "Debug" / "End" option in an error message, the
code will inevitably stop running and everthing is reset.
Applying proper error handling will alert you to the error and handle
it without asking you what to do. Thereby not resetting project.

Feb 4 '07 #2
on****@gmail.com wrote:
Now there seems to be a bit of a problem with these global objects:
when I'm running the application, at random times Access crashes when
the code accesses these global objects. Apparently, the instances are
sometimes reset by Access --- even though I'm not working on the code
and haven't recompiled anything explicitly.
Global variables are reset if there is an unhandled error. This doesn't occur in .MDE
files but does in .MDB files.

Add error-handling to appropriate procs.

Some classes can be re-instantiated but it doesn't sound like your class is a candidate if
it tracking other resources like open forms.

Public m_instanceYourClass As clsYourClass

Public Function returnObjectRef() As clsYourClass

If (m_instanceYourClass Is Nothing) Then
Set m_instanceYourClass = new clsYourClass
End If

Set returnObjectRef = m_instanceYourClass
End Function

air code. Something like that but this is just curing the symptoms and not the disease ;)
--
'---------------
'John Mishefske
'---------------
Feb 4 '07 #3
Hi John and storrboy,

Thanks for your replies! I'm afraid, though, that the whole project
has already been filled with error handling :) I'm pretty sure there
are no unhandled errors occurring.

I will try using John's code, but I think I already tried it once, to
no avail.

Yours sincerely,
Onno Broekmans

Feb 5 '07 #4
Hm.. I also tried storing the 'global objects' on a form, but the same
problem keeps popping up: Access crashing at random when a global
object is accessed.

Is there anyone here who has used one or more global objects in a
module (like a Collection, or a home-grown object) with success? If
so, it would mean there may be some other problem in my code?

Thanks again,

Yours sincerely,
Onno Broekmans

Feb 5 '07 #5
on****@gmail.com wrote:
Hm.. I also tried storing the 'global objects' on a form, but the same
problem keeps popping up: Access crashing at random when a global
object is accessed.
How did you do it?

When I follow this approach, I have a form, frmV (V for variables) with
numerous text boxes and possibly other controls on it. When I assign a
value to such a conytrol it's:

Forms.frmV.txtWindowsUserName = <whatever>

To access the variable in another form or module, I just refer back to
Forms.frmV.txtWindowsUserName
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
Feb 5 '07 #6


In the Tools>Options menu, try changing the 'Break On' option to
Unhandled Errors.
See if you notice a difference in when and how many errors occur.

Try finding a method that repeates the error consistantly. Step
through the code and carefully check all your variable values and see
if you can identify what is actually causing it. This should at least
narrow down what to investigate next.

Feb 5 '07 #7
Hi Tim,
Hm.. I also tried storing the 'global objects' on a form, but the same
problem keeps popping up: Access crashing at random when a global
object is accessed.
How did you do it?
I declared a public variable:

Public ViewManager As CViewManager

in a form frmSys, which was opened during startup and then hidden
(Visible=False). The variable was initialized in frmSys's Open event.
I also tried John's approach. It still seems Access 'randomly' resets
the project or so...

Yours sincerely,
Onno Broekmans

Feb 5 '07 #8
Hi storrboy,
In the Tools>Options menu, try changing the 'Break On' option to
Unhandled Errors.
See if you notice a difference in when and how many errors occur.

Try finding a method that repeates the error consistantly. Step
through the code and carefully check all your variable values and see
if you can identify what is actually causing it. This should at least
narrow down what to investigate next.
Thanks for the suggestion; I already have these settings set, though.
Perhaps I should indeed try stepping through the code some more. I
noticed some time ago, though, that when explicitly *stepping* through
the code in de debugger magically lets the errors disappear :)

I gave it some more thought, and it seems that most often pressing a
toolbar button causes the crash. Perhaps there could be some
(additional) problem regarding customized toolbars and toolbar buttons
bound to functions in a module?

Yours sincerely,
Onno Broekmans

Feb 5 '07 #9
On Feb 5, 2:00 pm, j.huibreg...@umail.leidenuniv.nl wrote:
Hi storrboy,
......
>
I gave it some more thought, and it seems that most often pressing a
toolbar button causes the crash. Perhaps there could be some
(additional) problem regarding customized toolbars and toolbar buttons
bound to functions in a module?

Yours sincerely,

Onno Broekmans
I once also had problems with custom toolbars, but I can't recall if
it reset the project or not.
I found that both calling subs and using functions that return values
or accept arguments in a toolbar's action did cause problems.
I have since stuck with only calling functions specific to the button.

example...

Button action: =DoThis()

Function DoThis()
'Run the actual required proceedure using need arguments and return
values
End Function

Feb 6 '07 #10
Well, just bad luck then, I guess; I already have just plain
functions :) I will try to look around some more for info on custom
toolbar problems; if I manage to solve this problem (and I hope I
will!), I will post the solution...

Thanks for your help, guys!

Yours sincerely,
Onno Broekmans

Feb 6 '07 #11
on****@gmail.com wrote:
Hm.. I also tried storing the 'global objects' on a form, but the same
problem keeps popping up: Access crashing at random when a global
object is accessed.
Maybe there is a touch of corruption in your Access database. Are you familiar with the
/decompile switch to decompile your .mdb file?

Make a backup, then compact and repair. Exit and use the /decompile switch to open the
database and then exit. Restart the app and compile and then Compact and Repair. Exit and
start again. See if that helps.

You can search Google on "access mdb decompile fenton" for more info.

--
'---------------
'John Mishefske
'---------------
Feb 7 '07 #12
Hi John,

Yeah, I decompile once in a while when things start to go crazy :)
Often this helps when you load the database the first time after
decompile, but when you close and re-open it, the crashes often come
back again. So I guess the problem's somewhere else... Thanks for the
suggestion, though!

Yours sincerely,
Onno Broekmans

Feb 8 '07 #13
on****@gmail.com wrote:
Hi John,

Yeah, I decompile once in a while when things start to go crazy :)
Often this helps when you load the database the first time after
decompile, but when you close and re-open it, the crashes often come
back again. So I guess the problem's somewhere else... Thanks for the
suggestion, though!
I believe you said earlier this problem didn't occur when you are single-stepping
through the code. I would try to localize the disappearing globals occurrance to
some activity if possible and then use breakpoints to step through your code
(instead of single-stepping).

Maybe you can narrow it down to a block of code.

Are you running any timers?

--
'---------------
'John Mishefske
'---------------
Feb 9 '07 #14
I did some additional testing, and came up with the following..
(Btw: I hope you don't mind me posting all this stuff in this group,
but I'm really stuck with this...)

It seems to boil down to Access:

*) crashing when I press a toolbar button that is coupled to a VBA
function, i.e. a Commandbar button having its "On Action" property [?
translated literally from Dutch] set to "=myFunction()".

or,

*) resetting the project just after a VBA-coupled button is pressed;
after that, the VBA function *is* called, but many global variables
have just become 'invalid'. Also, it crashes on one specific procedure
call --- just a normal procedure in a different module. Setting a
breakpoint on this procedure call and then stepping through the code
manually makes things go perfectly smooth!

or,

*) giving strange error messages that it "cannot compile the module"
just after pressing the button. After that, nothing works anymore.
Decompiling doesn't work, nor does importing all objects into a fresh
database. My project does contain one timer (only turned on in one
form's Form_Current, and used for a "delayed screen update"), but
disabling it doesn't solve the problem.

Also, I haven't been able to reproduce this behaviour in a test
database --- I'm still working on that one.

The workaround seems to be to just get rid of all the commandbars and
embed the commands into the forms, but just in case anyone has some
ideas... I'd be much indebted!

Thanks again,

Yours sincerely,
Onno Broekmans

Feb 9 '07 #15
>Decompiling doesn't work, nor does importing all objects into a fresh
>database. My project does contain one timer (only turned on in one
form's Form_Current, and used for a "delayed screen update"), but
disabling it doesn't solve the problem.

Two thoughts...

First...
When you import to a fresh database, are you importing the module or
copy/paste code.
This may be time consuming, but I once had to do this to repair a
corrupt form
- any object with a module that is viewable, export as text, or
copy and paste code to a text file.
- do the same to forms and reports, but afterward set the
HasModule property to No (False). This destroys the module object.
- import everything into a new DB and recreate modules from
exported files.
- Don't import menus - recreate them - if possible destroy the
old ones first and give the new DB as different name.
Someone once told me that menu corruption could occur when two
DBs of the same name contain the same menu.
Not sure if that's true or not, could never confirm it.

Second...
Do(es) the global object(s) that disappear have Terminate events?
If not add them and set some trivial executable code in it. Put a
breakpoint in this event.
If things are shutting down properly (even though their scope dies too
early), you should be able to step back into the offending calling
proceedure and see what the previous executed statement was - likely
the offending peice of code.

Or have you done all this already?

Feb 10 '07 #16
OK, I think I'm going to give up.
This may be time consuming, but I once had to do this to repair a
corrupt form
I followed all your steps, re-created the whole project (under a
different filename) from scratch, re-created all my toolbars with
different names... Nothing! Still exactly the same errors. That does
suggest there's something deeper going on, I'd say. Still no luck in
creating a test-case project from scratch, though :( It's very hard to
put a finger on the one specific property of my project that makes
Access crash.
Do(es) the global object(s) that disappear have Terminate events?
No, unfortunately not. I think I remember an old version, though,
where some global objects did have Terminate events --- they would not
be called. Also, during the crash all my forms close, but none of the
Form_Close event handlers gets called.

Well, thanks for your help so far; I think the only option is just to
get rid of all the custom toolbars. It's a shame, but if it solves my
problems...

Yours sincerely,
Onno Broekmans

Feb 11 '07 #17
I finally managed to produce a testcase: I imported some of the core
modules of my project into a fresh database (by copying/pasting the
code), and stripped them until only the strictly necessary functions
were left.

Pressing the custom button on my custom menubar crashes Access. I also
found that, indeed, just before the crash, a whole series of objects
is 'terminated'. I'm afraid that there's nothing to be found in the
call stack when I put a breakpoint in the Terminate event, though, so
I haven't been able to track down the cause.

Would someone have the opportunity to look at the testcase? It can be
found on:
http://www.onnodb.com/test4.mdb

Now I'm very much aware of the fact that looking at the code in this
test would take some time. Would someone be willing to do this? And
would it be possible to offer some sort of (financial?) compensation
for this, if necessary, or am I violating group regulations by doing
that? Or should I go somewhere else for that?

Yours sincerely,
A very grateful Onno Broekmans :)

Feb 11 '07 #18
On Feb 11, 1:52 pm, "onn...@gmail.com" <onn...@gmail.comwrote:
I finally managed to produce a testcase: I imported some of the core
modules of my project into a fresh database (by copying/pasting the
code), and stripped them until only the strictly necessary functions
were left.

Pressing the custom button on my custom menubar crashes Access. I also
found that, indeed, just before the crash, a whole series of objects
is 'terminated'. I'm afraid that there's nothing to be found in the
call stack when I put a breakpoint in the Terminate event, though, so
I haven't been able to track down the cause.
Just how random is the crashing? 1 in 100 times the menu button is
clicked? 1 in 10?
I clicked the menu button over 60 times in one running. The only error
I could produce was in clicking the menu button before running the
AutoExec. Restarted Access a couple of times and re-ran the program.
Could not get it to crash.

I have to wonder if you're correct in there being something else
wrong, perhaps with your installation of Access itself?
Feb 12 '07 #19
Hm... Weird. On my computer, it crashes 1 out of 1 :) The same problem
on a few other computers, also; and note that both my computer and the
others are fully updated using MS Update/Windows Update/Office Update.

Perhaps there is something else that triggers the error:
1) Add another custom toolbar to the project, call it something like
"testReview", dock it to the bottom.
2) Add a custom button to it, and let it call the same code as the
"Click me!" button in the custom menu, or similar code.
3) Add the following code to the MainForm Activate event handler:

CommandBars("testReview").Visible = True

4) Add the following code to the MainForm Deactivate event handler:

CommandBars("testReview").Visible = False

5) This once triggered the start of the crashes. (Note that one could
also use the "Toolbar" (?) property of the form to assign a commandbar
to it, but this code was once used to show/hide an *additional*
commandbar *conditionally*)

Perhaps I should consider resetting all the settings of Access? How
should I do this? Remove the Access.pip file in the Office program
directory?

Yours sincerely,
Onno Broekmans

Feb 12 '07 #20
on****@gmail.com wrote:
CommandBars("testReview").Visible = True

4) Add the following code to the MainForm Deactivate event handler:

CommandBars("testReview").Visible = False

5) This once triggered the start of the crashes. (Note that one could
also use the "Toolbar" (?) property of the form to assign a commandbar
to it, but this code was once used to show/hide an *additional*
commandbar *conditionally*)
With the exception of setting the command bar invisible in the on close
event of my forms, I do exactly what you describe above in many of my
apps in both A97 and A2003 and have never had a problem similar to what
you've been working on in this thread.

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Feb 12 '07 #21
Hi storrboy,
Just how random is the crashing? 1 in 100 times the menu button is
clicked? 1 in 10?
I clicked the menu button over 60 times in one running. The only error
I could produce was in clicking the menu button before running the
AutoExec. Restarted Access a couple of times and re-ran the program.
Could not get it to crash.
(Currently pulling my hair out)
Thanks a bunch for testing the file! I really appreciate your help...
I'll try a few other things, and test my own project on some other
computers. Or perhaps I should consider learning silicon voodoo :)
I have to wonder if you're correct in there being something else
wrong, perhaps with your installation of Access itself?
I'll try resetting/repairing Access...

Yours sincerely,
Onno

Feb 13 '07 #22
On Feb 13, 3:34 pm, "onn...@gmail.com" <onn...@gmail.comwrote:
Hi storrboy,
Just how random is the crashing? 1 in 100 times the menu button is
clicked? 1 in 10?
I clicked the menu button over 60 times in one running. The only error
I could produce was in clicking the menu button before running the
AutoExec. Restarted Access a couple of times and re-ran the program.
Could not get it to crash.

(Currently pulling my hair out)
Thanks a bunch for testing the file! I really appreciate your help...
I'll try a few other things, and test my own project on some other
computers. Or perhaps I should consider learning silicon voodoo :)
I have to wonder if you're correct in there being something else
wrong, perhaps with your installation of Access itself?

I'll try resetting/repairing Access...

Yours sincerely,

Onno

For what it's worth, I couldn't get it to crash either. In Access
2002 or 2003. I can't recall if you said you had tried to get this to
crash when converted to an MDE file. Have you tried that yet?

Bruce

Feb 13 '07 #23
On Feb 13, 3:34 pm, "onn...@gmail.com" <onn...@gmail.comwrote:
Hi storrboy,
Just how random is the crashing? 1 in 100 times the menu button is
clicked? 1 in 10?
I clicked the menu button over 60 times in one running. The only error
I could produce was in clicking the menu button before running the
AutoExec. Restarted Access a couple of times and re-ran the program.
Could not get it to crash.

(Currently pulling my hair out)
Thanks a bunch for testing the file! I really appreciate your help...
I'll try a few other things, and test my own project on some other
computers. Or perhaps I should consider learning silicon voodoo :)
I have to wonder if you're correct in there being something else
wrong, perhaps with your installation of Access itself?

I'll try resetting/repairing Access...

Yours sincerely,

Onno

My last two suggestions are (I'm out of ideas at this point)...

Use a RunCode macro in the menus OnAction property instead of the
function. Have the macro run the function currently being used.
I can't remember if you said this happens on more than one computer,
but if the above fails to work, try the DB in a fresh installation of
Access.
Other than that, I'm stumped.
Sorry.

Feb 14 '07 #24
Well, I tried reinstalling Access, but no luck there, either. I'm
currently looking for other computers with 'fresh' Access
installations to try to reproduce this --- which is going to be a
problem in itself, considering that you can't get the test db to
crash :(

Btw: using a RunCode macro produces exactly the same result: as soon
as I do *anything* that runs VBA code from within Access (either a
commandbar or a macro), apparently VBA starts recompiling things,
brings up funny error messages ("Can't compile module...") or crashes.

One last idea is that perhaps this is caused by me using Interfaces
and Events. Or perhaps I should try contacting MS support --- and pay
them a lot of money...

Anyway, I thank you sincerely for all your help --- it's been greatly
appreciated!! A million thanks!

Yours sincerely,
Onno Broekmans

Feb 19 '07 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Vani Murarka | last post by:
Hi Everyone, Does .NET offer any collection class which will give me objects last *accessed* such that I may build a least-recently-used cache that kills off objects that haven't been used for...
17
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm...
33
by: DFS | last post by:
An application I wrote has been deployed on Citrix, and the Citrix admin tells me all users run the same .mde file. There aren't a lot of concurrent users, but even 2 could be cause for concern. ...
33
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have...
19
by: Shiv Kumar | last post by:
I see that the Application_OnStart event is fired only once for a certain application. I'm interested in creating a "global" object (an object that will be available to all requests for the...
15
by: randyr | last post by:
I am developing an asp.net app based on a previous asp application. in the asp applications global.asa file I had several <object id="id" runat="server" scope="scope" class="comclass"> tags for...
1
by: Stu | last post by:
Hi, Im using vis studio 2003 and I think wse is out of the question as clients could be using java which doesnt support it. So I managed to find some code which allows you to develop a custom...
23
by: David Colliver | last post by:
Hi, using c#, 1.1 I know that we are not supposed to use global variables etc. in c# I am having a problem, but not sure how to resolve. I did have another post here, but may have over...
18
by: Donn Ingle | last post by:
Hi, I'm getting myself really confused. I have three classes. Two of them need to reference the third, like so: Canvas ---Stack <--- Thing I am doing this right now: s = Stack()
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.