Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple solution needed for retrieving name of currently logged-in user 5

Status
Not open for further replies.

sternaphile

Programmer
Jul 8, 2004
4
US
I'm not an Access pro. I need a simple solution for retrieving name of currently logged-in user, that I can (hopefully) put right into a field's default value in a table. Is there some sort of a #userid# reference, or something along those lines?

Thanks for your help in advance.
 
Try searching the Forum and FAQ's (tabs above) I know this has been answered before but can't remember the solution



Neil Berryman
IT Trainer
neil_berryman@btopenworld.com
 
Hi

If you are talking about the Access user as in Access Security, then see =CurrentUser()

If you are talking about Windows User, see Dev Ashish site for function to retieve Windows User

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Hi,

if you want the Windows logon id try UserName = VBA.Environ("UserName") no references or other coding required...

HTH, Jamie
FAQ219-2884
[deejay]
 
KenReay - Thanks for the Dev Ashish site - great resource. There was a nice code chunk there that retrieves the name for me.

jksmi - Great short & quick solution. Gets me the info that I need.

The problem I'm having with both solutions, is that I need to bind the result into a field, and I don't really have any idea how to go about it.
I've already successfully bound the current date/time to another field in my table by setting the field's default value to Now(). How would I go about binding the result of either of the suggested code blocks to a specific field(let's call it [Responder])in a table(let's call it [tblServiceCalls])?

Once again, thanks for your help.
 
Hi

Assuming you are using a (Bound) form to update the table

Have on the form a control ResponderId (with visible property set to false if you do not want user to see it)

In the Before Insert event of the form put coding

[ResponderId] = CurrentUser()

or

[ResponderId= = MyFunctionName()

depending on which user id you are talking about (MyFunctionName() is the name of the function which retrieves the Windows Login Id)

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - [URL unfurl="true"]www.kenneth.reay.btinternet.co.uk[/URL]
UK
 
In a standard code module:
Public Function getWinUser() As String
getWinUser = Environ("UserName")
End Function
Then when in form design view right click on the Responder control, choose properties, tab Data, Default value :
=getWinUser()

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PH,

PERFECT - Exactly what I needed. Short, sweet, and to the point. Thank you greatly!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top