Can I get an Access 2010 variable to be global? (1 Viewer)

GregoryWest

Registered User.
Local time
Today, 07:40
Joined
Apr 13, 2014
Messages
161
What I am trying to do seems simple, but the exact method eludes me.


What I need is when (unique for each user/session) an Access accdb is opened, three global variables are created and default values are set. These variables need to be active throughout the users session and keep any user updates during the session. Once the session is over, the variables are no longer important.


At first I thought of just creating a small side table with the three variables as fields. The only problem with this, is multiple people in the same accdb concurrently needing different values in their individual copies of the variables.


Anyone ever done anything like this? Is there a simple elegant solution to this problem?
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 08:40
Joined
Apr 27, 2015
Messages
6,358
Easily done, give this article a read. Type Variables are you answer...

I use this method to record user information at startup and the variable are available throughout the session.

https://analystcave.com/vba-the-vba-type/
 
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 13:40
Joined
Feb 19, 2013
Messages
16,627
At first I thought of just creating a small side table with the three variables as fields. The only problem with this, is multiple people in the same accdb concurrently needing different values in their individual copies of the variables.
Sounds like you have not split your database, put the backend (tables) on the server and provided each user with their own copy of the front end (everything else) located on their machine.

Failing to split a database will lead to corruption at some point. That corruption will be irreversible and you will lose all forms, reports, code and most importantly, your data.

If it was split, then each user could have their own local table, or you can use tempvars or global variables
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:40
Joined
May 7, 2009
Messages
19,247
if multiple users will be using the db you need to split the db. move the table with var to the front end. then you distribute the fe.

or add another field to the table, that uniquely associates to the user. say UserID, 1 belongs to user1, 2 to userw, etc.
 

June7

AWF VIP
Local time
Today, 04:40
Joined
Mar 9, 2014
Messages
5,486
Declare global variables in a general module header. Keep in mind that global variables lose their values when code run-time errors. This can be quite annoying during debugging.

I've never tried the Type statement. No idea if has same issue. Try it and let us know.

Other alternatives are 1) save data on a form that never closes so always available for reference or 2) TempVars.

Definitely split the database.
 
Last edited:

NauticalGent

Ignore List Poster Boy
Local time
Today, 08:40
Joined
Apr 27, 2015
Messages
6,358
Completely overlooked the shared dB bit. That is way I will never be as cool as you guys. GregoryWest, if you are not using a split DB and you have multiple users, you should make learning about split Access DB’s your one and only priority and then come back to this issue once you have.
 

GregoryWest

Registered User.
Local time
Today, 07:40
Joined
Apr 13, 2014
Messages
161
I agree with you 100%. Right now, just working up a 'Proof of concept'. The end user will have to choose which back-end database they want it on in the end.



Sounds like you have not split your database, put the backend (tables) on the server and provided each user with their own copy of the front end (everything else) located on their machine.

Failing to split a database will lead to corruption at some point. That corruption will be irreversible and you will lose all forms, reports, code and most importantly, your data.

If it was split, then each user could have their own local table, or you can use tempvars or global variables
 

Users who are viewing this thread

Top Bottom