Glabal Variables losing values in vba, MS ACCESS

Hi,
I have a "main" module in my access application . In that module I store global variables such as
Global AUTHENTICATED_USER_LOGIN_NAME As String

On log-in form i assign value to that variable and expect to work with it on each form of my application. Sometimes my globals loose value, but sometimes it works fine. Any idea why it happens? Any possible solutions?

thanks
maximyshkaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
where are you setting the value for AUTHENTICATED_USER_LOGIN_NAME variable?

and when you said the variable loses the value, in what particular event did this happened?

storing a variable value in a non visible opened form is one way to make certain the variable value is available in your application, just a note of work around
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Globals lose their value for several reasons, but the main cause seems to be unhandled errors in your code (i.e. when Access throws up the Error box). If you include error handling in ALL code, this seems to be one way to minimize the danger of losing that value.

That said, I agree with Cap re: using a hidden form. This is the best way to insure that you never lose that value for the specific session.
0
maximyshkaAuthor Commented:
The problem is i can't catch where it looses value. i have a lot of code. Sometimes it works perfectly and sometimes it is just doesn't work...

I don't think that invisible form is efficient way. Do you think that it is access bug?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

maximyshkaAuthor Commented:
you right i don't use error handling all the time.
0
maximyshkaAuthor Commented:
code works , access doesnt show any error...
0
Rey Obrero (Capricorn1)Commented:
<I don't think that invisible form is efficient way.> this is the most reliable way.

< Do you think that it is access bug?> NO.. the reason is already stated by LSM.
0
jefftwilleyCommented:
A table driven setup is also a way to go (depending on the number of public variables that you have)

Store your variable values into a table where they can be retrieved at any time and reassigned to the variable.

A class to do this is a very handy mechanism and easy to maintain.

.02

J
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
<i have a lot of code. Sometimes it works perfectly and sometimes it is just doesn't work...>

It's unfortunate that you chose to not follow proper programming practices when you originally developed your application, but unfortunately there's little you can do at this point except go back and fix those areas where you have erred.

There are some 3rd party utilities that may help. My favorite is MZ Tools (www.mztools.com), which is free and includes an error handler tool that will add error handling to all your subs and functions.
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
<I don't think that invisible form is efficient way>

Why? You've already opened the form (your login form); just set .Visible = False instead of using DoCmd.Close, and you're done? There is no additional overhead to maintain that form, and you can refer to it as needed. This is a tried-and-true part of the programmer's toolbox.

Although JTW's method of storing them in a table is a good idea also.
0
llewesCommented:
I gave up on this problem a few years back - too many unpredictable outcomes.
My solution - I use the Switchboard which I modify in all sorts of ways.
It stays open for the duration of a session.
I setup my variables here and have never had a problem in many databases over a number of years
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
llewes: This is essentially the same suggestion made by Cap in the original comment:

"storing a variable value in a non visible opened form is one way to make certain the variable value is available in your application"

Generally, when simply posting a "me too" comment you should attribute the original comment
0
llewesCommented:
LSMConsulting

Thank you so much for the generous sharing of your wit and wisdom.

Amazing!
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
llewes: I was simply commenting on the policies in place here at Experts Exchange. As Cap had already made the suggestion, there's no reason for you to have also done so a day later.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.