473,785 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access Forgets Global Variable!!

This is a strange one.

I have an app that needs to know who is using the program but there's no
need for security. When the program opens a form comes up with a listbox.
The user double-clicks his name, the data is stuffed into a variable that is
dimmed in a module, and the user is "logged in".

From time to time, though, Access forgets the value! There is no other place
in the database where the variable is written. This is happening in 2002,
but I've seen this problem in 97 too.

The work-around is no problem. I just stuff the user name into a table when
the user logs in and get the data from there. But it just blows me away that
this variable comes up blank every once in a while.

Anybody else seen this? What could be the problem?

Thanks!

Mike
Nov 13 '05 #1
8 2467

"Mike Turco" <mi*******@yaho o-no-spam-4-me.com> wrote in message
news:K10Zd.1088 42$bu.39614@fed 1read06...
This is a strange one.

I have an app that needs to know who is using the program but there's no need
for security. When the program opens a form comes up with a listbox. The user
double-clicks his name, the data is stuffed into a variable that is dimmed in
a module, and the user is "logged in".

From time to time, though, Access forgets the value! There is no other place
in the database where the variable is written. This is happening in 2002, but
I've seen this problem in 97 too.

The work-around is no problem. I just stuff the user name into a table when
the user logs in and get the data from there. But it just blows me away that
this variable comes up blank every once in a while.

Anybody else seen this? What could be the problem?


If you have an unhanded error in an MDB (not an MDE) then variables will often
lose their values.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #2
If your application (your code) encounters a error, then all global (and in
fact all) variables are re-set. You loose their values.

There is two solutions to this problem:

1) make sure you always have error handling code for each routine

2) Since I don't always follow #1, then distribute your application as a
mde, and un-handled errors will NOT reset your variables (both local, and
global).

So, while it is standard recommend and practice to distribute a mde so users
can't change, and mess with things, using a mde also have many other added
benefits in terms of reliability of your application.

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com
http://www.members.shaw.ca/AlbertKallal
Nov 13 '05 #3

"Albert D. Kallal" <ka****@msn.com > wrote in message
news:B21Zd.6662 92$6l.393911@pd 7tw2no...
If your application (your code) encounters a error, then all global (and
in fact all) variables are re-set. You loose their values.

There is two solutions to this problem:

1) make sure you always have error handling code for each routine

Interesting! Is "on error resume next" at the top of the sub not good
enough? What about something like the following?

Sub Test()

On Error Goto Test_err

docmd.this
docmd.that
exit sub

Test_err:
select case err.number
case 1:
msgbox "Oops, you typed that 300 digit number wrong"
resume next
case 2:
resume next
case else
msgbox err.number & ": " & err.description
resume next
end select
2) Since I don't always follow #1, then distribute your application as a
mde, and un-handled errors will NOT reset your variables (both local, and
global).


This particular app is going to be distributed run-time anyway, so I might
as well distribute the mde. I'm still a little surprised, though. I didn't
know that encountering an error reset all your variables and its even more
of a surprise that I've only seen this issue crop up twice in the past ten
or so years.

Mike
Nov 13 '05 #4
"Mike Turco" <mi*******@yaho o-no-spam-4-me.com> wrote in
news:d83Zd.1093 35$bu.7432@fed1 read06:

"Albert D. Kallal" <ka****@msn.com > wrote in message
news:B21Zd.6662 92$6l.393911@pd 7tw2no...
If your application (your code) encounters a error, then all
global (and in fact all) variables are re-set. You loose
their values.

There is two solutions to this problem:

1) make sure you always have error handling code for each
routine


Interesting! Is "on error resume next" at the top of the sub
not good enough? What about something like the following?

Sub Test()

On Error Goto Test_err

docmd.this
docmd.that
exit sub

Test_err:
select case err.number
case 1:
msgbox "Oops, you typed that 300 digit number
wrong" resume next
case 2:
resume next
case else
msgbox err.number & ": " & err.description
resume next
end select
2) Since I don't always follow #1, then distribute your
application as a mde, and un-handled errors will NOT reset
your variables (both local, and global).


This particular app is going to be distributed run-time
anyway, so I might as well distribute the mde. I'm still a
little surprised, though. I didn't know that encountering an
error reset all your variables and its even more of a surprise
that I've only seen this issue crop up twice in the past ten
or so years.

Mike

There is another way of holding the user's ID. Keep the form
open, and refer to the form's control.You make the form invisible
instead of closing it. It's how I handle this situation.
--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #5
"Mike Turco" <mi*******@yaho o-no-spam-4-me.com> wrote in
news:K10Zd.1088 42$bu.39614@fed 1read06:
I have an app that needs to know who is using the program but
there's no need for security. When the program opens a form comes
up with a listbox. The user double-clicks his name, the data is
stuffed into a variable that is dimmed in a module, and the user
is "logged in".

From time to time, though, Access forgets the value! There is no
other place in the database where the variable is written. This is
happening in 2002, but I've seen this problem in 97 too.


Why not hide the form that the user double-clicks on and instead of
referring to the global variable, either refer to that form, or, if
you worry about performance, then use a function, something like
this (which is self-healing if the global variable is reset):

Public Function GetUser() As String
Static strUser As String

If Len(strUser) = 0 Then
strUser = Forms!dlgUserNa me!lstUsers
End If

GetUser = strUser
End If

You'll note that it will look it up from the hidden form only if the
Static variable gets reset. I prefer this method to using global
variables when the variable is set only once or can be retrieved
from some other source (such as a lookup or a Windows API call).

Of course, you'll want to handle the case where the dialog form gets
closed.

Another alternative if you're intending to store it in a table (I'd
never do that -- I might consider storing it as a custom property of
the MDB file, though) is to have this function do the table (or
customer property) lookup if the static variable has been reset.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #6

"David W. Fenton" <dX********@bwa y.net.invalid>
Another alternative if you're intending to store it in a table (I'd
never do that -- I might consider storing it as a custom property of
the MDB file, though) is to have this function do the table (or
customer property) lookup if the static variable has been reset.


The variable does go into a table, anyway, because I want the database to
remember the variable between sessions. Rather than refer to the variable
directly I call a function. If the variable is empty then the function looks
up the value in the table. The variable only dumps out occasionally so its
not a performance issue.


Nov 13 '05 #7
On Sun, 13 Mar 2005 23:19:37 -0800, "Mike Turco"
<mi*******@yaho o-no-spam-4-me.com> wrote:

"David W. Fenton" <dX********@bwa y.net.invalid>
Another alternative if you're intending to store it in a table (I'd
never do that -- I might consider storing it as a custom property of
the MDB file, though) is to have this function do the table (or
customer property) lookup if the static variable has been reset.


The variable does go into a table, anyway, because I want the database to
remember the variable between sessions. Rather than refer to the variable
directly I call a function. If the variable is empty then the function looks
up the value in the table. The variable only dumps out occasionally so its
not a performance issue.


Well, you've stumbled across a very good answer for handling cached values in
VBA. Populate the variable unless it's already populated. That way, if you
ever reset the program, the program will recover transparently.
Nov 13 '05 #8

"Steve Jorgensen" <no****@nospam. nospam> wrote in message
news:i9******** *************** *********@4ax.c om...
On Sun, 13 Mar 2005 23:19:37 -0800, "Mike Turco"
<mi*******@yaho o-no-spam-4-me.com> wrote:

"David W. Fenton" <dX********@bwa y.net.invalid>
Another alternative if you're intending to store it in a table (I'd
never do that -- I might consider storing it as a custom property of
the MDB file, though) is to have this function do the table (or
customer property) lookup if the static variable has been reset.


The variable does go into a table, anyway, because I want the database to
remember the variable between sessions. Rather than refer to the variable
directly I call a function. If the variable is empty then the function
looks
up the value in the table. The variable only dumps out occasionally so its
not a performance issue.


Well, you've stumbled across a very good answer for handling cached values
in
VBA. Populate the variable unless it's already populated. That way, if
you
ever reset the program, the program will recover transparently.


That works well for me.

I was trying to create that mde, by the way. Turns out I can't do it because
I'm using A2002 and the file needs to stay in A2000 format. Since I'm
distributing the run-time for some of the computers, I hope there are no
other little surprises :-)

Mike
Nov 13 '05 #9

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

Similar topics

44
2040
by: Mohanasundaram | last post by:
int i = 10; int main() { int i = 20; return 0; } Hi All, I want to access the global variable i inside the main. Is there
1
9131
by: Machi | last post by:
let say i have a web form with a button on it ... when i click the button, it will pop up one small window to allow me to save a pdf file, everything is done using code behind as below ... however, in javascript, i have set a global variable as a flag to indicate the number of times user click the buttion (let say flagNoOfClick), when user clicks the button once, it will set the flag (flagNoOfClick) to "true" (by using javascript). So, when user...
9
2543
by: ruca | last post by:
How can I declare a global variable in my .js file, that I can preserve her value each time I need to call any function of .JS file in my ASP.NET application? Example: var aux=null; function myFunction1() { ...
1
6563
by: anjud | last post by:
I have an external javascript file which contains a global variable - arrNames var arrNames=new Array(); arrNames="FirstName"; arrNames="LastName"; In my html page I had given the path of this external script file as <head> <script language="javascript" type="text/javascript" src="Common.js"></script>
9
356
by: Shilpa | last post by:
Hi, I just wanted to know whether we can access global variable within a local block , where both variables are having same name. For ex: int temp=5 ; { int temp=10;
112
5481
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions that may print some messages. foo(...) { if (!silent)
20
12761
by: teddysnips | last post by:
Weird. I have taken over responsibility for a legacy application, Access 2k3, split FE/BE. The client has reported a problem and I'm investigating. I didn't write the application. The AutoExec macro calls a function "InitApplication" which, in turn, calls a function to set the value of a global string variable
4
3722
Dheeraj Joshi
by: Dheeraj Joshi | last post by:
Hi, I was wondering is there any technique available, so we can access the global variable inside a function if we have a local variable inside the function with the same name as global variable. Example #include<something.h> int countVal = 100; /* Some stuff */
3
1994
by: jay manu | last post by:
i have two buttons, which are disabled on page load, when i select one radio button i have to make that button enable. But when i write button1.Enable() in the radibutton click event, its showing an error "global object 'button1' not defined. How can i tackle this problem. How can i access a global variable in another function?
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8978
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.