1

I have an access table with a column username. I have multiple users that will use the database at different times and they will add rows to the table. But everytime a user add a new row, his/her username must appear in the username column of the table, without them having to type it in by themselves. I tried putting in UCase(Environ("USERNAME")) as the default value, but Environ is an unknown function. I use this UCase(Environ("USERNAME")) in VBA to get the user name when i export tables.

Is there any way i can set the deafult value of a column to a user's username?

Jason Samuels
  • 951
  • 6
  • 22
  • 40
  • How are the users adding records to the table? If your answer is directly, then there is your problem ! If they are using Forms, then you could make use of the Form's button events. – PaulFrancis Oct 07 '14 at 09:53
  • They will add it like they would with a normal table, but the table will be viewed within a form (a form within a form). But thanks for the tip. I will look into button events and i also don't mind using VBA to do it if that is the way to go. – Jason Samuels Oct 08 '14 at 06:13

1 Answers1

3

Create a public function as described here:

Public Function GetUserName() As String
    ' GetUserName = Environ("USERNAME")
    ' Environ("USERNAME") is easily spoofed, see comment by HansUp
    GetUserName = CreateObject("WScript.Network").UserName
End Function

and use =GetUserName() as default value for the control.

Community
  • 1
  • 1
Andre
  • 26,751
  • 7
  • 36
  • 80