get real user name

PeteJM

Registered User.
Local time
Today, 16:31
Joined
Oct 31, 2004
Messages
28
Hi, can anyone help

I use the code =Environ("username") provided by people on this forum to return the username of te person logged into the database. This works fine but...

Wouldit be possible to create a function using this code to return the users real name.

I have a table T_Staff with fields S_Name and S_Username

The username field stores the same username as that returned by the code.

I was thinking that if it could be done as a function i could reference that function in the forms i use. e.g =realname()

Thanks for taking time to read my request.

Regards

Pete
 
You can use Environ("Username") as the criteria in a query and pull the real name from the UserTable.

Col
 
Pete,
Not sure what you want done exactly but heres a simple solution:
Table:
tblUser
Fields:
ID: Primary Key
UserID:
UserName:
UserRole:
Make a Query , call it qry1, ensure it has the fields UserID and UserName. In the criteria for the UserID field put this in : Forms![formname]![fieldname].value where this value is the textbox with control scource =Environ("username").
Make sure you enter the details for the above fields in the table.
I dont know if your using a login form or not, anyhow, on the form that has the textbox(Control Scource:=Environ("username")) that you use to display the current logged in user, place anther text box and give its control scource this criteria:=DLookUp("[UserName]","[qry1]")
Using this method the Form will display the User ID and User Name of the person logged in by looking up qry1. Make sure you have entered the Users Name in tblUser and always follow Business Directory Formats :D as they say.
If you have any problems let me know.
Best Regards,
Chris
________
XV1600A
 
Last edited:
You can grab the users full name [First Last] using the API at Dev's site. It works as posted. For a quick test just add this function to the module.

Code:
Function TestGetFullNameOfLoggedUser()
    MsgBox fGetFullNameOfLoggedUser
    'MsgBox fGetFullNameOfLoggedUser(Environ("UserName")) 'either should work
End Function

Here is the link to the API... API: Get full name of the user currently logged in to the system

Just copy the entire page of code into a new module and add the function I listed above to test it.

The Environ function has a lot to offer...

Code:
MsgBox Environ("UserDomain")
MsgBox Environ("UserName")
MsgBox Environ("ComputerName")

Check out this thread for a function that will list all Environ variables your computers operating system will provide... Get Current User Name and Computer Name
 

Users who are viewing this thread

Back
Top Bottom