Re: Global variables disappear
- From: "Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx>
- Date: Fri, 2 Dec 2005 10:23:41 +0800
When testing your code, you often reset (Run | Reset, from code window), or
perform an operation that causes that effect. That destroys your public
variables.
While that is less likely in a production environment, it is an issue, and
it certainly makes it difficult to debug. When I first started in Access, I
created an extra public boolean variable, set it to True, tested it before
using any variable, and if not set, called the Init() function again.
Realistically, that's more trouble than it's worth, so now I don't use any
global variables at all. The only exception is where the built-in procedures
don't allow me to pass what I need, and so the lifetime that I need to rely
on is almost instantaneous.
You can use a hidden control on a form to hold a value that survives a
reset. For an extended lifetime (e.g. something that survives to the next
time you open the database again), you can write the value to a table. And
for your own functions, you can always pass the argument to the lower level
procedure.
HTH.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Teewan" <Teewan@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:375454A6-CDB5-403E-A49C-EDFC14651311@xxxxxxxxxxxxxxxx
> Hi guys
>
> I have a training database, which I am still making alterations to and am
> disturbed that sometimes while working on forms etc my Global variables
> are
> suddenly all zero length strings.
>
> On opening the database the system startup opens the Switchboard form.
> The OnOpen event of the Switchboard form calls a number of functions
> located
> in the SysConfiguration module which sets the Global variables to their
> appropriate values. Every now and then those values suddenly revert to
> zero
> lenght strings for no apparent reason.
>
> It has been suggested to me that they are attached to the Swithchboard
> form
> and I would loose them when I close the Switchboard. If this is the case
> how
> and where should I be setting them from. Incidentally, I can't seem to
> make
> them zero by closing the Switchboard.
>
> I wondered if it is just a glitch occurring because I'm stopping and
> starting bits of code etc. It doesn't seem to have happened (as yet) when
> the database is being used by the average user working in there, only in
> my
> testing versions. It is making me very nervous though as I use a Global
> prefix for many of my Primary keys.
>
> Thanks in advance
> Teewan
.
- Follow-Ups:
- Re: Global variables disappear
- From: Teewan
- Re: Global variables disappear
- Prev by Date: Re: Quit & Open (OT)
- Next by Date: Re: Any way of using in VB AllowAdditions for a subform?
- Previous by thread: Re: How do I insert the results of an Access query into email w/ grid
- Next by thread: Re: Global variables disappear
- Index(es):
Relevant Pages
|