Bonjour,

Je commence sur VBA et j'aimerais extraire des informations depuis un LDAP (serveur LDAP différent d'un contrôleur de domaine AD). J'arrive à me connecter mais j'ai un problème avec mon recordset pour extraire les données.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 
Sub Extract_LDAP()
Dim objConnection, objCommand, objRecordSet, objFSO, objF
Dim sName, strPath, strName, strManager, StrTmp
Const ADS_SCOPE_SUBTREE = 2
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
strName = "output.csv"
strPath = ".\"
If (objFSO.FileExists(strPath & strName)) Then
objFSO.DeleteFile strPath & strName
End If
Set objF = objFSO.CreateTextFile(strPath & strName)
objF.Close
Set objF = objFSO.openTextFile(strPath & strName, ForAppending)
 
sUser = "admin"
sDN = "cn=" & sUser & ",dc=company,dc=com"
sRoot = "LDAP://127.0.0.1:1389/dc=company,dc=eu"
 
Dim oDS: Set oDS = GetObject("LDAP:")
Dim oAuth: Set oAuth = oDS.OpenDSObject(sRoot, sDN, "password", 0)
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider", sDN, "password"
Set objCommand.ActiveConnection = objConnection
 
objCommand.Properties("Page Size") = 100
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
 
objCommand.CommandText = "SELECT attribut1,attribut2 FROM 'LDAP://127.0.0.1:1389/OU=people,dc=company,dc=com'" & "WHERE objectClass='person'"
Set objRecordSet = objCommand.Execute
 
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
 
Do Until objRecordSet.EOF
sName = objRecordSet.Fields("attribut1").Value
 
strDescription = ""
If Not (IsNull(objRecordSet.Fields("attribut2").Value)) Then
For Each StrTmp In objRecordSet.Fields("attribut2").Value
strManager = StrTmp
Next
End If
 
objF.WriteLine (sName & ";" & strManager)
objRecordSet.MoveNext
Loop
objF.Close
 
End Sub
L'erreur pointe sur la ligne suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
For Each StrTmp In objRecordSet.Fields("attribut2").Value