I have a form, that I added textbox to, and I want the textbox to display the windows user name that is inputting the data. So I put =winusername() in the Default value of the text box, but it is producing only #Name? Please help
I have a form, that I added textbox to, and I want the textbox to display the windows user name that is inputting the data. So I put =winusername() in the Default value of the text box, but it is producing only #Name? Please help
did you define the function winusername()? or you just assume that Access should have that function built in?
I get the windows user name by a user defined function "username()" as following(in a module):
Code:Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Function UserName() As String Dim lngLen As Long Dim strBuffer As String Const dhcMaxUserName = 255 strBuffer = Space(dhcMaxUserName) lngLen = dhcMaxUserName If CBool(GetUserName(strBuffer, lngLen)) Then UserName = Left$(strBuffer, lngLen - 1) Else UserName = "NoUser" End If End Function
You can use the Environ() function or this:
http://www.mvps.org/access/api/api0008.htm
I tried both codes, but it is still displaying #Name?. My remaining question is:
When I input the function into a module, how do I tell access to call this function from the textbox that I want the username input in? Or does access automatically regonize the funtion and will display the username once the function has been input?
Access will look for it.
when I tried, it works. not sure where you stuck.
Just to make sure I do it correctly. I would hit F10 to open up VBA editor, and then say insert module. From there I would copy and paste the code, and name the code whatever. Once the code is inserted, I would go back to my textbox, and in the default value insert =winusername() and access should display the windows name correcT?
For the method I posted, you would copy/paste the code as-is into a new module, name the module anything but "fOSUserName", then in your textbox:
=fOSUserName()
Nevermind, I didn't change the =winusername to =UserName and that is where the error was coming into play. Thanks for the help!