Thanks Duane Hookom. I used that code. But I have another problem. My code
is below.
When I run the code, an error "Activex component can't create object". I
have referenced activeds.tlb.
Do I miss anything?
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
Public Function Test()
Dim MyUser As IADsUser
Dim MyCommonName As String
Dim u As String
u = fOSUserName()
' Bind to a specific user object.
Set MyUser = GetObject("LDAP://CN=" & u, "user")
' Get property
MyCommonName = MyUser.Name
MsgBox (MyCommonName)
End Function
----- Original Message -----
From: "Duane Hookom" <duanehookom@NO_SPAMhotmail.com>
Newsgroups: microsoft.public.access.modulesdaovba
Sent: Wednesday, October 27, 2004 10:34 PM
Subject: Re: How to get current logon domain username and domain name in
access 97?