Question Identifying Database user

StevieAllen

New member
Local time
Today, 14:19
Joined
May 12, 2017
Messages
3
Hi all, I'm very new to the Access world and I am just finding my feet building a small database for the team I work for. I have a question about something that I'm hoping is quite easy for you guys to advise me on

There will be 5 people that use the database I am creating and what I want to do is when each person opens the database it recognises who they are, eg:Hello Steve....

I have a table that contains all the users and their user ID's, is it possible to use this to be able to do what I require?

Many thanks for any help in advance

Steve
 
If they login to the database then its easy to link to the user info in this way.
Use something like:
Code:
" Hello " & DLookup("Forename", "tblUsers", "UserID = '" & Me.UserID & "'")

If not, you could use:
Code:
"Hello " & Environ("UserName")
This will return the name used to login to the computer
 
If they login to the database then its easy to link to the user info in this way.
Use something like:
Code:
" Hello " & DLookup("Forename", "tblUsers", "UserID = '" & Me.UserID & "'")

If not, you could use:
Code:
"Hello " & Environ("UserName")
This will return the name used to login to the computer


Thank you :) I will put this in now and see if it works! Thanks again for replying
 
If they login to the database then its easy to link to the user info in this way.
Use something like:
Code:
" Hello " & DLookup("Forename", "tblUsers", "UserID = '" & Me.UserID & "'")

If not, you could use:
Code:
"Hello " & Environ("UserName")
This will return the name used to login to the computer

Would I create a text box for this code to go in?
 
Yes or use a label where this is the caption
 
Last edited:
Stevie, there are many places where this could go and we can infer (from your original question and your response to ridders) that you are not excessively comfortable with VBA and a few other things yet.

Places you can put this sort of thing:

1. When you open any form, a Form_Open event "fires" and can be used to do some things not involving controls on the form (because they haven't been set up yet). Since the event allows for a "Cancel" operation, you can use that as a way to stop people from opening forms based on their role in the database.

What I did was to look up the Environ("Username") to see who had logged in to the domain (because we had a domain-based environment). I then could do DLookup from a table of authorized DB users to see what role they had. If their role said a particular form was not for them, I used the Cancel option and the form wouldn't open for them.

In the Form_Open routine, you can do this lookup and copy the value of the Environ call to a variable declared in the form's declaration area.

2. After the form opens (i.e. you DIDN'T use the Cancel option), a Form_Load event fires. Here, if you have a control such as a text box where you WANT to show the logged in username, you could assign the value of the Environ function to that box with simple VBA.

3. It is possible in a text-oriented control to assign the .ControlSource property to a function value, as =Environ("Username"), which would get loaded during the Form_Load event WHETHER OR NOT you had event code. Then other things on or in the form could look at the contents of that text box.

The .ControlSource method would also work on reports.
 

Users who are viewing this thread

Back
Top Bottom