....how to get the emails address that are in the active directory
I tried changing the select statement to this to try and show the IT departments email or even every member of the IT Departments email. However ended up showing one person email in the department
CommandText = "SELECT mail FROM 'LDAP://" & DomainDN & "' WHERE department = 'Information Technology'"
Public Function GetEmails(ByVal DeptName As String) As Object
"SELECT mail FROM 'LDAP://" & DomainDN & "' WHERE department '=" & DeptName & "'"
Set Me.comboname.Recordset = GetEmails(Me.txtDepartment)
Set Me.listboxname.Recordset = DeptEmails(Me.Department)
Public Function DeptEmails(ByVal DeptName As String) As Object
Const adOpenStatic = 3
Const adUseClient = 3
Dim DomainDN As String
Dim ADConn As Object 'ADODB Connection
Dim rs As Object 'ADODB.Recordset
DomainDN = CreateObject("[URL]ldap://rootDSE").Get("defaultNamingContext[/URL]")
Set ADConn = CreateObject("ADODB.Connection")
With ADConn
.Provider = "ADsDSOObject"
.Open "Active Directory Provider"
End With
Set rs = CreateObject("ADODB.Recordset")
With rs
.ActiveConnection = ADConn
.Source = "SELECT mail FROM 'LDAP://" & DomainDN & "' WHERE objectCategory='User' AND department ='" & DeptName & "'"
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.Open
.ActiveConnection = Nothing
End With
ADConn.Close
Set DeptEmails = rs
Set ADConn = Nothing
Set rs = Nothing
End Function
I I just tried to add it to my database, but received an error message that it couldn't create the object. Is there a reference that needs to be added so that this will work?
Also, is it possible to use wild cards when the function is called?
whatever = "*foo*"
Dim DomainDN[B] [COLOR=Red]As Object[/COLOR][/B]
[COLOR=Red][B]Set[/B] [/COLOR]DomainDN = CreateObject("ldap:\\rootDSE").Get("defaultNamingContext")