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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I retrieve the user's username

Status
Not open for further replies.

matpj

Technical User
Mar 28, 2001
687
GB
I have used the security wizard to set up some users with passwords in my database.

I want to be able to retrieve the current user's username, so that when they create a new record, a field is stamped with their username. Is this possible?

Also, it should be stamped there and not overwritten each time someone else views the record.

thanks,
Matt
 
Matt,

The following KB article details sample functions for retrieving user and group information in your database.


If you create a function to pull the current user, you can set the function as the default value of a text box in the form. That way when the new record is written using the form, the user's information is automatically included.

Let me know if I can be of further assistance!
Ami
AmiDenise@yahoo.com
 
Hi Matt!

You can use the CurrentUser function to get the user's name and store it in the record when it is created. You should be able to create a field in the table and set its default value to CurrentUser.

hth
Jeff Bridgham
 
private sub Form_BeforeUpdate()
me.UserID=currentuser
me.UpdateTime=now() 'It will be good that you would create Date/Time field for saving last update time together with currentuser
end sub

Aivars
 
Aivars,

I tried your method first, but nothing happens.
I created a text box called UserID
I entered the code: me.UserID = currentuser
but nothing happens.

the field is left blank
 
It kind of worked - I didn't realise I needed to save the record.
There is a problem though.
Once that is done, the same user name appears in the text box on all records, and when I log off and on as somebody else the box is then blank.

how can I get only the current record to be updated, and only upon creation of the record. So that when somebody else edits the record it is still only the person who created it whose name is present?
 
Create fields named UserID (Text) and field UpdateTime (Date/Time) in table.

Aivars
 
Thank you that now works, although how do I make the field so that it is not overwritten?
I only want the field to be filled in once, byt the creator of the record, not by people editing the record
 
matpj,

Somehow my first response took a left turn in the system and ended up in another posting. Try the following code in your form:
Code:
Private Sub Form_BeforeInsert(Cancel As Integer)
  Me!UserID = CurrentUser
End Sub
 
jfischer,

will this only stamp the field once? (look at my posting just above yours)

I need the field locked so that only the person that created the record is logged - not subsequent editors!

thanks,
Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top