Hallo,
hier der Codeausschnitt:
'Get the domain string ("dc=domain, dc=local")
Dim strDomain As String
strDomain = "OU=FIRMA Benutzer,DC=FIRMA,DC=net"
' ADODB Connection to AD
Dim objConnection As ADODB.Connection
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
' Connection
Dim objCommand As ADODB.Command
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
' Search the AD recursively, starting at root of the domain
Dim Searchfield As String
Dim Returnfield As String
Dim SearchString As String
SearchString = "*@firma.net"
Searchfield = "mail"
Returnfield = "samaccountname,displayname,company,physicaldeliveryofficename,l,customgeschlecht"
objCommand.CommandText = "<LDAP://" & strDomain & ">;(&(|(customgeschlecht=männlich)(customgeschlecht=weiblich)(samaccountname=sonderuser))(objectCategory=User)" & "(" & Searchfield & "=" & SearchString & ")(!(userAccountControl:1.2.840.113556.1.4.803:=2)));" & Returnfield & ";subtree"
objCommand.Properties("Page Size") = 20
objCommand.Properties("Sort On") = "displayName"
' RecordSet
Dim objRecordSet As ADODB.Recordset
Set objRecordSet = objCommand.Execute
If objRecordSet.RecordCount = 0 Then
MsgBox ("Keine Verbindung zum Datenbankserver möglich!") ' no records returned
Else
invenioMA.Clear
Do Until objRecordSet.EOF
If Not IsNull(objRecordSet.Fields("samaccountname")) Then
invenioMA.AddItem (objRecordSet.Fields("samaccountname"))
invenioMA.List(invenioMA.ListCount - 1, 1) = objRecordSet.Fields("displayname")
End If
If Not objRecordSet.EOF Then
objRecordSet.MoveNext
End If
Loop
End If
Da es sich um ein Word Macro handelt, fällt das temp. speichern in ein Tabellenblatt aus.
Das Speichern in eine temp. txt/csv wäre denkbar, aber da liegt die Datei ja dann langfristig.. Wäre bednklich.
Ich würde gerne das Form, welches das Listboxelement enthält gerne anzeigen während das Listbox noch befüllt wird...
Danke,
Andreas
|