Ppeterso
15 pts. | Aug 26 2009 3:15PM GMT
How does Access capture the NT username? What is the advantage of Access providing the user name verses SQL Server?
btw..thanks for the above answer.
Randym
1410 pts. | Aug 27 2009 2:08PM GMT
If you use linked tables, the logon would be the same for all users of the Access application unless you relink the tables for each Access user. The same goes if you use DAO in VB code. The NT user user is specific to who ever is logged on at that PC running the application at that time. This code works in Access 2003 to get the OS user. You can also use Access security which can be separate from the OS security.
Option Compare Database
Option Explicit
Private Declare Function GetUserNameA Lib “advapi32.dll” (ByVal lpBuffer As String, nSize As Long) As Long
Public Function UserLoggedOn() As String
Dim cn As String
Dim ls As Long
Dim res As Long
cn = String(1024, 0)
ls = 1024
res = GetUserNameA(cn, ls)
If res <> 0 Then
UserLoggedOn = Mid(cn, 1, InStr(cn, Chr(0)) - 1)
Else
UserLoggedOn = “”
End If
End Function






