CptPicard
asked on
automatically assign user when adding a new record
Using Access 2010. Wondered if there's a way that when a user clicks the 'Add Record' button to add a new record, it could automatically place their name into a field called 'user' which is invisible to the user but is used so as to keep a record of which user is adding the data. I could therefore create a report to show which users have added the data. I'd rather it be automatic rather than the user having to select their own username each time they add a new record if that's at all possible. I'm assuming you'd need a login form first where the user gets to choose their username (but no password). It would have to some how remember their username for every form they access and add data too. Is this possible?
Yes, it is possible...
You are correct in the fact they would need a Login form so that Access recognizes the current user. Here is something to get you started:
SELECT ID, [Employee Name] FROM [Employees Extended] ORDER BY [Employee Name];
So the field would initially show the selected user (from the Login form) and allow for your to choose any other employee from the table.
As far as hiding the field, it's just a matter for setting the value of "Visible" to 'No'.
It's been a while since I've used Access. I'm going to go fire it up and see if I can get you more information.
-Chris
You are correct in the fact they would need a Login form so that Access recognizes the current user. Here is something to get you started:
SELECT ID, [Employee Name] FROM [Employees Extended] ORDER BY [Employee Name];
So the field would initially show the selected user (from the Login form) and allow for your to choose any other employee from the table.
As far as hiding the field, it's just a matter for setting the value of "Visible" to 'No'.
It's been a while since I've used Access. I'm going to go fire it up and see if I can get you more information.
-Chris
What about using the system username the user has logged on with? The username can be obtained using the Environ function:
Environ("username")
If domain is also required, you can use:Environ("domainname") & "\" & Environ("username")
Create a new column, called UserName in your table. In the event that adds new record (button clicked event for 'Add Record' button) add this code (provided you have a RecordSet called rs):rs.UserName = Environ("domainname") & "\" & Environ("username")
If you have troubles with that, send us the 'Add Record' function, and we will help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This works perfectly!
Thanks for everyone's help with this!
Thanks for everyone's help with this!
Then on each form BeforeUpdate if Me.NewRecord add the UserID to that record.