global variable

  • Thread starter Thread starter grace
  • Start date Start date
G

grace

Guest
I have set up two global variables in my access application, UserID, TicketID. whenever a user logs into the system, these two variables will be set to proper value. The userid variable never changes during the session; and the TicketID variable is changed whenever user adds a new ticket into the application. The problem with these global variables are sometimes, they just become NULL. I hope somebody can tell me what I should do to avoid it from happen, or what should I pay attention to when using global variables.
 
Proper programmer's response:

Don't ever use global variables. Any variables you need access to (bad pun - I deserve to be drug out into the street and shot) or change you should pass as parameters.

Practical programmer's response:

Be careful if you use them.

What I say:

If you don't use them, fine. If you do, just be careful.

- Matt

[This message has been edited by Matt Leidemer (edited 06-14-2000).]
 
I have only noticed this problem with a database still in development. If an error occurs causing the code to stop and throw you into Debug - Sometimes - the global variables would disappear. As an alternative to globals, you can create a form with unbound fields that you can use to store the global data. You can open the form in your startup and hide it so it is never seen. A second alternative and the only one that works from session to session is to create a table with a single row to hold stored variables. Of course this only works if the users have a local copy of the code database so each instance of the database has a distinct table. If the users share a networked copy of the code database, the table would need to be keyed by UserID and you would still need to keep either the hidden form field or a global for UserID although the other variables could be stored in the table.

[This message has been edited by Pat Hartman (edited 06-14-2000).]

[This message has been edited by Pat Hartman (edited 06-14-2000).]
 

Users who are viewing this thread

Back
Top Bottom