
Originally Posted by
pbaldy
You'd want a standard module, not a class module. Also make sure you don't name the module the same as the function.
Thank you for clearing that up. The website said to name it the same but I changed the name of the Module 'UserName'. I listed the code for the module below. If the module was created correctly, how do I use it? Do I create an event for a new record that says.
Code:
me.[Path to field to change] = fOSUserName()
?
Code:
Option Compare Database
Option Explicit
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