What is the code for a VBA macro that gets the users name when the Access DB is on Win NT4.0?<br><br>This has been answered before I have lost the thread.<br><br>Sorry.
Code****<br><br> ' Declare for call to mpr.dll.<br> Declare Function WNetGetUser Lib "mpr.dll" _<br> Alias "WNetGetUserA" (ByVal lpName As String, _<br> ByVal lpUserName As String, lpnLength As Long) As Long<br><br> Const NoError = 0 'The Function call was successful<br><br> Sub GetUserName()<br><br> ' Buffer size for the return string.<br> Const lpnLength As Integer = 255<br><br> ' Get return buffer space.<br> Dim status As Integer<br><br> ' For getting user information.<br> Dim lpName, lpUserName As String<br><br> ' Assign the buffer size constant to lpUserName.<br> lpUserName = Space$(lpnLength + 1)<br><br> ' Get the log-on name of the person using product.<br> status = WNetGetUser(lpName, lpUserName, lpnLength)<br><br> ' See whether error occurred.<br> If status = NoError Then<br> ' This line removes the null character. Strings in C are null-<br> ' terminated. Strings in Visual Basic are not null-terminated.<br> ' The null character must be removed from the C strings to be used<br> ' cleanly in Visual Basic.<br> lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)<br> Else<br><br> ' An error occurred.<br> MsgBox "Unable to get the name."<br> End<br> End If<br><br> ' Display the name of the person logged on to the machine.<br> MsgBox "The person logged on this machine is: " & lpUserName<br><br> End Sub <br><br>*****End Code*****<br><br>I know that I have used variations on this successfully. I think you will probably need to do further string manipulations of the result; as I remember the result has some funky characters at the end.<br><br>Good luck<br><br>Kathryn
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.