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
</ldap:></ldap:>
#!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
Last edited: