Querying AD information Through VBA Error

balla506

New Member
Joined
Sep 10, 2012
Messages
32
I have tried numerous ways to get this to work and keep getting an "atrribute syntax specified to the directory service is invalid". I am new to active directory and have never used nonrational database querying before. It seems to connect fine but after that no matter what I try it will not get past the cmd.Execute line. Any help would be appreciated.


#!SEARCH REQUEST (27) OK
#!CONNECTION ldap://gc.net:328
#!DATE 2018-02-12T13:54:26.984
# LDAP URL : ldap://gc.net:328/ou=DeptTree,ou=Lookup,ou=Services,o=BC?DTDeptDesc,objectClass?sub?(cn=x011)
# command line : ldapsearch -H ldap://gc.net:328 -x -D "cn=Sys,ou=serviceaccounts,ou=services,o=bc" -W -b "ou=DeptTree,ou=Lookup,ou=Services,o=BC" -s sub -a always -z 1000 "(cn=x011)" "DTDeptDesc" "objectClass"
# baseObject : ou=DeptTree,ou=Lookup,ou=Services,o=BC
# scope : wholeSubtree (2)
# derefAliases : derefAlways (3)
# sizeLimit : 1000
# timeLimit : 0
# typesOnly : False
# filter : (cn=x011)
# attributes : DTDeptDesc objectClass

#!SEARCH RESULT DONE (27) OK
#!CONNECTION ldap://gc.net:328
#!DATE 2018-02-12T13:54:27.002
# numEntries : 1


Code:
Sub EDSQuery()
'Dim base As String
'Dim fltr As String
'Dim scope As String
'Dim attr As String




'Sets the Base
base = <ldap: eds.net:320"="" &="" "="">"<ldap: gc.net:328"="" &="" "="">"


'Sets a filter for the query
fltr = "(cn=x011,ou=serviceaccounts,ou=services,o=bc)"


'Set the Attributes
attr = "DeptHierList"
scope = "Subtree"


Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADsDSOObject"
conn.Open "LDAP Query", "cn=Sys,ou=serviceaccounts,ou=services,o=bc,", "Pa$$"




Set cmd = CreateObject("ADODB.Command")
Set cmd.ActiveConnection = conn


'MsgBox base
'MsgBox fltr


MsgBox base & ";" & fltr & ";" & attr & ";" & scope


cmd.CommandText = base & ";" & fltr & ";" & attr & ";" & scope


cmd.Properties("Page Size") = 1000
cmd.Properties("Timeout") = 0
cmd.Properties("Cache Results") = False


 Set rs = cmd.Execute


Do Until rs.EOF
    MsgBox rs.Fields("postalCode").Value
    rs.MoveNext
Loop


rs.Close


conn.Close


End Sub
</ldap:></ldap:>
 
Last edited:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Found my error in the LDAP portion. I was mixing two queries so I was calling an attribute that did not exist. Once changed it worked, but now I am having trouble doing something with the recordset created. I have tried
Code:
Recordset.recordcount
but get an error. If I try to use the code the Access Application just locks up and I get the spinning wheel of death.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top