How can I insert user name in a field in a table automatically
If you are not going to use Form for your table, there are steps to follow:
1. create a Table for your username:
tblUser (table)
ID (autonumber)
user (short text)
2. add a single record to tblUser (any text).
3. create a public function that will update tblUser with the username
public function fnUpdateUser()
currentdb.execute "update tbluser set user = '" & environ$("username") & "'"
end function
4. create a macro and save it as autoexec (the name).
Runcode
Function name fnUpdateUser()
5. bring your table in design view.
add Data Macro (Before Change)
Look Up A Record In tblUser
Where Condition [ID] = 1
----
SetLocalVar
----
Name tvarUser
----
Expression [tblUser].[user]
SetField
Name [theUsernameFieldHere]
Value =[tvarUser]
''''''''''''''''''''''''''''''
save your table and restart your app.