Access LDAP through Access 2010 & VBA

RetiredInVero

New member
Local time
Today, 15:46
Joined
Jan 29, 2016
Messages
3
I am trying to write a procedure to update LDAP user attributes from within a little Access database/application. Below is all the pertinent information. Hopefully someone can help. TIA
---------------------
Microsoft Visual Basic being used from within Access 2010.
Microsoft Visual Basic for Applications 7.0, Version 1637
Running MS Windows 7 Professional 64 bit, SP 1
I am trying to update the user account attributes by using objUser.Put commands.
The user executing this code has full read/write permissions to AD and is a domain administrator with full rights. The user can manually add, delete and modify objects (users, etc.) in AD using the MS AD tools. We are trying to automate this process.
The account that is being used for this test definitely exits. It was created specifically for this testing.
This code opens the object with no error
Set objUser = GetObject("LDAP://OU=USERS,DC=CompanyName,DC=org")
When adding a specific user an error is generated
Set objUser = GetObject("LDAP://sAMAccountName=mis.test,DC=CompanyName,DC=org")
Error message: Run-time error '-2147016656(80072030)': Automation error There is no such object on the server.
This message is wrong. The account that is being used for this test definitely exits. It was created specifically for this testing.
I have tried various combinations and permuttations of using OU, no OU, etc. with no luck.
Any help would be appreciated.
 
It could be that the ADsPath in your GetObject statement is not properly formed. You might try getting the ADsPath via an LDAP query.

Also, your code assumes that your Active Directory is maintained on the Domain Controller. You might check with your IT Administrator that they do not have a secondary server for the Active Directory (ex. activedirectory.CompanyName.org)

Assuming that the Active Directory is maintained on the Domain Controller, you might try code like the following:
Code:
[COLOR="Navy"]Const[/COLOR] ADS_SCOPE_SUBTREE = 2

[COLOR="Navy"]Dim[/COLOR] cnADSD [COLOR="Navy"]As Object
Dim[/COLOR] cmADSD [COLOR="Navy"]As Object
Dim[/COLOR] rsADSD [COLOR="Navy"]As Object

Dim[/COLOR] objUser [COLOR="Navy"]As Object

Set[/COLOR] cnADSD = CreateObject("ADODB.Connection")
[COLOR="Navy"]With[/COLOR] cnADSD
    .Provider = "ADSDSOObject"
    .Open "Active Directory Provider"
[COLOR="Navy"]End With

Set[/COLOR] cmADSD = CreateObject("ADODB.Command")
[COLOR="Navy"]Set[/COLOR] cmADSD.ActiveConnection = cnADSD
cmADSD.Properties("Timeout") = 30
cmADSD.Properties("Searchscope") = ADS_SCOPE_SUBTREE
cmADSD.Properties("Cache Results") = [COLOR="Navy"]False[/COLOR]

cmADSD.CommandText = "SELECT ADsPath FROM 'LDAP://DC=CompanyName,DC=org'" & _
    " WHERE sAMAccountName='mis.test'"
[COLOR="Navy"]Set[/COLOR] rsADSD = cmADSD.Execute
[COLOR="Navy"]If[/COLOR] rsADSD.EOF = [COLOR="Navy"]False Then

    Set[/COLOR] objUser = GetObject(rsADSD.Fields("ADsPath"))

    [COLOR="DarkGreen"]' Insert Put/SetInfo code here[/COLOR]
    objUser.Put "employeeID", "12345" [COLOR="DarkGreen"]' Example
    ' ...[/COLOR]
    objUser.SetInfo

    [COLOR="Navy"]Set[/COLOR] objUser = [COLOR="Navy"]Nothing

End If[/COLOR]

rsADSD.Close
[COLOR="Navy"]Set[/COLOR] rsADSD = [COLOR="Navy"]Nothing

Set[/COLOR] cmADSD = [COLOR="Navy"]Nothing[/COLOR]

cnADSD.Close
[COLOR="Navy"]Set[/COLOR] cnADSD = [COLOR="Navy"]Nothing[/COLOR]
 
Code:
Set objUser = GetObject("LDAP://CN=Users,DC=CompanyName,DC=org")
 
There is also the issue to consider that the item referenced by "DC=string" has to exist on the server, so I would verify spelling of the domain AS SEEN BY THE CONTROLLER.

(It doesn't matter how YOU see it.)
 
To all,
Thanks for all of the responses. I really appreciate it.
The code I displayed, particularly the LDAP object string, was just the text version of what I assembled using the proper methods for assembling the string.
ByteMyzer I tried your code and your method of opening the object seems to have worked, didn't get an error. And with a slight delay seems to have worked fine. So thank you again. I am looking at your code and the original parts of my code that I seem to have remarked out, and the parts I didn't "think" I needed were the exact match to yours. So much for over thinking.

Once again that you all for the wonderful and prompt responses.
 

Users who are viewing this thread

Back
Top Bottom