Hello-
I'm trying to display Windows username on a form and also have it write to the associated field in my table.
I successfully accomplished this using the same code (below) in a different form in my DB.
However, when I use the code in a new form within that same DB, I get the #Name? error.
The error occurs even when the Private Sub is commented out and the Public function stands alone.
The only change I made was to the field name.
Triple-checked the accuracy in spelling and syntax.
Also added "=GetUserName() to the control as a source.
Issue still present.
Please help! Completely stumped.
Code:
Public Function GetUserName() As String
GetUserName = Environ("UserName")
End Function
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me![ADDED_BY] = GetUserName()
End Sub