Link to home
Start Free TrialLog in
Avatar of maximyshka
maximyshka

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maximyshka
maximyshka

ASKER

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?
you right i don't use error handling all the time.
code works , access doesnt show any error...
<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.
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
<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.
<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.
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
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
LSMConsulting

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

Amazing!
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.