Hello it's me again, an novice access user.
I am trying to set the default value of a textbox for new records to Environ("Username"), I was able to get this to work by using the code below.... with default value set to =fOSUserName()
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
' Returns the network login name
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
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function
I tried to use the one below with default value set to =getWinUser(), but it didn't work so i decided to stick to the one above
Public Function getWinUser() As String
getWinUser = Environ("UserName")
End Function
I have created a table named "tblTeamMember" that contains the username and the TeamMemberName (e.g. username andysmith, TeamMemberName ANDY SMITH). I want to match the value returned from fOSUserName() with the value that is in TeamMemberName field. Will this code work?
Me!LoggeBy= DLookup("TeamMemberName", "UserName='" & Environ("USERNAME") & "'")
On what event should i put the code in? Please help....![]()