Using a Global Variable

scotthutchings

Registered User.
Local time
Today, 02:53
Joined
Mar 26, 2010
Messages
96
I have a field in each table to store information about who created and last modified a record as well as a time stamp when it occurred. I currently have it set up that the user must manually enter their initials (or select their name from a drop down field). How do I set it up so the user must log in when they first open the application and then use that information automatically whenever I need it to (How do I set the value of a global variable and then access that value when needed?)

Thanks in advance!
Scott
 
Scott,

Welcome to the forums.

Here is a link that will show you how to get the UserName of the user that is logged in.
http://www.mvps.org/access/api/api0008.htm

If you create a table of users (you'll also need a form to allow an Admin user to create other users in the table) and you store their UserName that you know will be retuned when they open the applicaiton, their actual name, a password and perhaps even a user access level. Then with the UserName you can get their actual Name and what their password should be. When your application starts up you present your login form, displaying their name and a text box where they can enter their password. When they have entered their password, check to see that the value entered is equal to the password you have in your table for that user and if it is, you continue opening the application if not, you notify the user that they are not authorized to use the applicaton and the exit the application.

This is not a totally secure method but if you have designed you application correctly and you have managed to neven allow the user out of your application except through your interface, and you have disabled the use of the Shift key when the application is opened, then this method should be sufficient to detur most folks from attempting to use the application without logging in.
 
Check out the "Sample Databases" part of the forum. One of the admins has a great example posted of a log in interface. One thing I may warn you against is that if you go the public variable route, it may be a pain when testing/creating your database because if your code hits an error the public variables do not retain their values. That is why i usually store the values in an unbound control on a form. So for example using the after update event all you have to code is:
LoginFormName.UserNameControl.Value

Just set whatever field you store your entry tracking info in equal to this and you are good to go, it is just as short as public variable and won't cause you agony when your code breaks.

Just as Mr. B points out, you can then query your users table with this value from the unbound control and hence customize user roles very easily. You can check passwords very easily using dlookup - there should be examples of this on this or other forums.
 
if you need to store the data from one session to another you can store it in the registery
 
What advantage does storing data in the registry provide over storing data in a table?
 
for multi user application each user will have it's oun data. this data can be easily be used in query.
you can use multiple row table (a row for each user) but how can you use this in query if you don't konw the user ?

it's by far easier to be used then using a table

global varaibles are good, but they can't be used in querys. they live in code only.

if you need a global data that will be used by all users it must be kept in a table.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom