Solved

vba search ldap

Posted on 2006-06-12
5
927 Views
Last Modified: 2008-01-09
I'm in access and I want to in vba search a ldap (active directory) for a certain user and grab there display name and email address. I have achived this in c# but for vba I know it is 100% different.

Can someone please show me in coding how to do this..

thanks
0
Comment
Question by:bman9111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:bpmurray
ID: 16888774
Try something like this:


    ' This is specific to your installation, but it's something like this
    Dim ADsPath As String
    ADsPath = "LDAP://directorydev.experts.com/aid=???,ou=Applications,o=experts.com,c=ie"
   
    ' Define the ADO connection
    Dim connection As ADODB.connection
    Set connection = New ADODB.connection
    connection.Provider = "ADSDSOObject"
    connection.Properties("User ID") = "cn=Directory Manager"
    connection.Properties("Password") = "foobar"
    connection.Open "ADSI"

   
    ' We need a command
    Dim command As ADODB.command
    Set command = New ADODB.command
    command.ActiveConnection = connection
    ' I'm not sure about this syntax
    command.CommandText = "<" & ADsPath & ">;(userreferencedn=*xternal*);ADsPath;subtree"
     
    ' This is returned as a data set
    Dim recordset As ADODB.recordset
    Set recordset = command.Execute
    recordset.MoveFirst
    While Not recordset.EOF
        ' Process the returned value
        recordset.MoveNext
    Wend
       
    ' OK we're finished - drop the connection
    connection.Close
0
 
LVL 8

Author Comment

by:bman9111
ID: 16888836
what parts am I suppose to replace with my data???

0
 
LVL 8

Author Comment

by:bman9111
ID: 16888857
meaning my domain name is

Hutwork

Username is Jted
Password is Ted

and I need to see what the user display name which would be

Jimmy Ted

Any ideas
0
 
LVL 8

Author Comment

by:bman9111
ID: 16890469
any ideas???
0
 
LVL 15

Accepted Solution

by:
bpmurray earned 500 total points
ID: 16892617
Unfortunately, I don't have access to an ADS right now, so I can't be sure this will work. However, type it in, and see how well it works. The idea is to pass in the "JTed" as a parameter, i.e. ShortName, and the data should then be returned. As I said, I haven't been able to test it, but it's pretty darn close :-)



Sub getUserInfo(shortName)

    ' Define the ADO connection
    Dim connection As ADODB.connection
    Set connection = CreateObject("ADODB.Connection")
    connection.Provider = "ADSDSOObject"
    ' You may have to provide your AD manager credentials here
    connection.Properties("User ID") = "cn=Directory Manager"  'YOURS
    connection.Properties("Password") = "foobar" 'YOURS
    connection.Open "ADs Provider"

   
    ' We need a command
    Dim command As ADODB.command
    Set command = New ADODB.command
    command.ActiveConnection = connection
   
    ' Set up the command ...
    Set rootDSE = GetObject("LDAP://RootDSE")
    DomainContainer = rootDSE.Get("defaultNamingContext")
    CommandStr = "<LDAP://" & DomainContainer & ">;(&(objectCategory=user)(mailNickname=" & shortName & "));ADsPath;subtree"
     
    ' This is returned as a data set
    Dim recordset As ADODB.recordset
    Set recordset = command.Execute(CommandStr)
    recordset.MoveFirst
    While Not recordset.EOF
        ' Process the returned value
        FullName = GetProperty(sResultSet, "cn")
        FirstName = GetProperty(sResultSet, "givenName")
        MiddleInitials = GetProperty(sResultSet, "initials")
        LastName = GetProperty(sResultSet, "sn")
        Address = GetProperty(sResultSet, "homePostalAddress")
        recordset.MoveNext
    Wend
       
    ' OK we're finished - drop the connection
    connection.Close

End Sub
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 116
numbers ascending pyramid 101 242
Java Loop 6 74
MacOS and programming in React 7 47
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question