Need Current User Name

Jwy

Registered User.
Local time
Today, 07:50
Joined
Sep 19, 2005
Messages
10
I need to mine the Proper Name of the current user and automatically populate a field on a form. I've tried default value = currentname() and all I get returned is Admin. How can I retrieve the Proper Name of the network username and auto populate a field? Any help is appreciated.
 
I need a little more help with the syntax. I tried =currentuser(environ("UserName")) with no success. I tried =environ("UserName") with no success. I am adding this code to the Default Value property of a field on a form. Should I be handling this another way? This seems like a very simple thing to accomplish, but I'm having trouble. I appreciate your help.
 
Download the LogOn 2000 Db from http://www.access-programmers.co.uk/forums/showthread.php?t=64532

It has a module to get the user name:

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fGetOSUserName() As String
On Error GoTo fGetOSUserName_Err

Dim lngLen As Long, lngX As Long
Dim strUserName As String

strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)

If lngX <> 0 Then
fGetOSUserName = Left$(strUserName, lngLen - 1)
Else
fGetOSUserName = ""
End If


fGetOSUserName_Exit:
Exit Function

fGetOSUserName_Err:
MsgBox Err.Description
Resume fGetOSUserName_Exit

End Function

Then refer to it on your form:

Me.txtUsername = fGetOSUserName

Dave
 
Or, in the Form_Open event handler, set the default value of the field.
Code:
Private Sub Form_Open(Cancel As Integer)
  Me.SomeField.DefaultValue = Environ("Username")
End Sub
 
Still no luck, lagbolt. I used your code example as suggested, but received "#Name?" in the RequesterName field on the form.
 
If you are referring to the textbox, make sure that the textbox's name is different than the field name. For example, if your field (in the table) is named Text1, then make sure the textbox that is bound to that field is named differently (txtText1).
 

Users who are viewing this thread

Back
Top Bottom