Declare the following api call in a module -
Public Declare Function getUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
- and then add a function like this -
Public Function getUser() As String
'Generic function to return the NT user name
'Used for security requirements
Dim strBuffer As String * 255
Dim lngLength As Long
Dim lngI As Integer
strBuffer = Space(255)
lngI = getUserName(strBuffer, 255)
getUser = Mid(strBuffer, 1, (InStr(1, strBuffer, Chr(0)) - 1))
'This line to cut out any null strings that may appear at the end
End Function
When you call this function your code, it will return the logged users sign on. There is also a getUserID api but it appears to call the exact same function.
Brendan