Global Variable loose value, when and how I don't know ... please help!

G

Guest

How can I find out at what point a Global variable loose its value on an end user machine while they are entering in a new record

Environment is Front End sits on local machine, data sits on a server. My Main Menu form contains a subform that when a user wants to add or edit a record a set the object source of my subform to the frmEditData form

Me.frmViewAll.SourceObject = "frmEditData

I then set a global variable gsubfrm to Form_frmEditDat

Set gsubfrm = Form_frmEditDat

The reason is that the sub form frmViewAll could be any one of 20 forms and each one of the 20 forms contain public function like canSave. They have these functions so that when a use click on my toolbar my canSave function on my main menu form has the comman

canSave = gsubfrm.canSav

The error that occurs is that gsubfrm becomes Nothing but I don't now why, the forms have all worked fine for years and its only after a recent upgrade has this fault appeared but not for all users. The problem does not arise if the data is stored on the local machine and for other users they don't have this problem. Could it be that if a network error occurs global variable values are lost

Any help would be great

TI
KM
 
S

Sandra Daigle

Hi Kevin,

Global variables typically get lost when there is an unhandled run time
error. This would be my primary reason for avoiding them as much as
possible.

I have a couple of guidelines for globals

- I only use them if their value is supported by a table or some other
source that I can use to restore the value.

- I don't (or rarely) use true public variables, instead I use module level
variables and obtain their values from a function. This procedure contains
logic to verify that the value is initialized and to reinitialize it if
necessary. Often I'll wrap several related values in a class, then have one
function getXYZ which returns an instance of the class which is maintained
in a module level variable. The function can easily verify whether the
variable is nothing and then set it and initialize it if necessary. As an
example of this I have a table that stores UserProfile information. When my
application loads the UserProf class is instantiated and loaded with the
correct values from the table for the current user. The getCurrentUser
function returns the global instance of the class (reinitializing when
necessary).

Another way many developers handle the need for global variables is to
create a form which is opened and hidden during application startup. Then
create controls on this form for global values. Caching a form object could
be done through this form, either by name or as an object if you create the
object as a public variable in the form's class module.
 
W

Wayne Morgan

I suspect the error that might be causing this (as Sandra mentioned, the
loss can be due to an error) is that a subform isn't "open". It is
considered to be a part of the main form and is referred to that way, not
directly as you would a normal form. Also, I suspect that even if the form
wasn't a subform but was open as a regular form that
Set gsubfrm = Form_frmEditData <
should be
Set gsubfrm = Forms!frmEditData

If gsubfrm was a text variable, would storing the name of the subform
instead of the subform itself help?

--
Wayne Morgan
Microsoft Access MVP


Kevin McCartney said:
How can I find out at what point a Global variable loose its value on an
end user machine while they are entering in a new record.
Environment is Front End sits on local machine, data sits on a server. My
Main Menu form contains a subform that when a user wants to add or edit a
record a set the object source of my subform to the frmEditData form.
Me.frmViewAll.SourceObject = "frmEditData"

I then set a global variable gsubfrm to Form_frmEditData

Set gsubfrm = Form_frmEditData

The reason is that the sub form frmViewAll could be any one of 20 forms
and each one of the 20 forms contain public function like canSave. They have
these functions so that when a use click on my toolbar my canSave function
on my main menu form has the command
canSave = gsubfrm.canSave

The error that occurs is that gsubfrm becomes Nothing but I don't now why,
the forms have all worked fine for years and its only after a recent upgrade
has this fault appeared but not for all users. The problem does not arise if
the data is stored on the local machine and for other users they don't have
this problem. Could it be that if a network error occurs global variable
values are lost?
 
A

Albert D. Kallal

If you have global vars..and UN-handled errors..you loose the values.

However, if you distribute a mde..that is NOT the case.

Have you tried giving each users a mde for the front end?

For the above reason...distributing a mde to your users is a good idea...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top