
Originally Posted by
June7
This is probably beyond my means to even try. I can't imagine that just anyone on the network would be able to do what you want, surely would need network administrator permissions to read those files. As for passwords, seems even administrator can't retrieve those. When I forget mine the admin has to reset.
I stupidly missed the fact that there was a sample file that could be downloaded. I now have that and the relevant code from it. when I change the LDAP string to point to my domain it then looks up my UID and returns a popup with the details that I want in it (name\department etc). Can you help me with working out how to get that information into a form instead of in a pop up?
This is the code that I pulled from the sample database.
Code:
Private Sub cmdSample3_Click()
'Note: Code to search Active Directory given the user login name.
'Note: Change 'LDAP://DC=Fabrikam,DC=COM' to your domain.
Dim varInfo As Variant
varInfo = ""
Dim LN As Variant
LN = InputBox("Enter Login:")
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT Name,AdsPath,givenName,SN,title,telephonenumber,Department,OU, CN, initials, displayname, " _
& "sAMAccountName, distinguishedName, physicalDeliveryOfficeName, mail,wWWHomePage,homePhone,pager,mobile,ipPhone,Info " _
& "FROM 'LDAP://DC=Fabrikam,DC=COM' WHERE " _
& "objectCategory='user' And sAMAccountName = '" & LN & "'"
Set objrecordset = objCommand.Execute
If objrecordset.EOF And objrecordset.BOF Then
objrecordset.Close
MsgBox "No Records match."
Exit Sub
End If
objrecordset.MoveFirst
'Return Active Directory information.
Do While Not objrecordset.EOF
varInfo = "Name = " & objrecordset.Fields("Name").Value & Chr(10) _
& "AdsPath = " & objrecordset.Fields("Adspath").Value & Chr(10) _
& "givenName = " & objrecordset.Fields("givenName").Value & Chr(10) _
& "SN = " & objrecordset.Fields("SN").Value & Chr(10) _
& "title = " & objrecordset.Fields("title").Value & Chr(10) _
& "Telephonenumber = " & objrecordset.Fields("telephonenumber").Value & Chr(10) _
& "Department = " & objrecordset.Fields("Department").Value & Chr(10) _
& "CN = " & objrecordset.Fields("CN").Value & Chr(10) _
& "OU = " & objrecordset.Fields("OU").Value & Chr(10) _
& "Displayname = " & objrecordset.Fields("Displayname").Value & Chr(10) _
& "Initials = " & objrecordset.Fields("Initials").Value & Chr(10) _
& "PhysicalDeliveryOfficeName = " & objrecordset.Fields("PhysicalDeliveryOfficeName").Value & Chr(10) _
& "Mail = " & objrecordset.Fields("Mail").Value & Chr(10) _
& "wWWHomePage = " & objrecordset.Fields("wWWHomePage").Value & Chr(10) _
& "HomePhone = " & objrecordset.Fields("HomePhone").Value & Chr(10) _
& "Pager = " & objrecordset.Fields("Pager").Value & Chr(10) _
& "Mobile = " & objrecordset.Fields("Mobile").Value & Chr(10) _
& "ipPhone = " & objrecordset.Fields("ipPhone").Value & Chr(10) _
& "Info = " & objrecordset.Fields("Info").Value & Chr(10) _
& "distinguishedName = " & objrecordset.Fields("distinguishedName").Value & Chr(10) _
& "sAMAccountName = " & objrecordset.Fields("sAMAccountName").Value & Chr(10) _
MsgBox varInfo
objrecordset.MoveNext
Loop
End Sub
Below is the link where I found the sample database if anyone wants to see it.
http://www.dbforums.com/6296643-post48.html