Okay so I know how to send an email using access but I wanted to know if anyone knows how to get the emails address that are in the active directory
Thanks
Okay so I know how to send an email using access but I wanted to know if anyone knows how to get the emails address that are in the active directory
Thanks
Maybe you can get some info using the techniques in this thread.
https://www.accessforums.net/code-re...ame-38386.html
Thanks, I ended up using this:
Public Function EmailAd(Optional ByVal LoginName As String) As String
Const adCmdText = 1
Dim ADConn As Object 'ADODB Connection
Dim ADCommand As Object 'ADODB Command
Dim ADUser As Object
Dim DomainDN As String
If LoginName = vbNullString Then
LoginName = CreateObject("wscript.network").UserName
End If
DomainDN = CreateObject("LDAP://rootDSE").Get("defaultNamingContext")
Set ADConn = CreateObject("ADODB.Connection")
With ADConn
.Provider = "ADsDSOObject"
.Open "Active Directory Provider"
End With
Set ADCommand = CreateObject("ADODB.Command")
With ADCommand
.ActiveConnection = ADConn
.CommandType = adCmdText
.CommandText = "SELECT mail FROM 'LDAP://" & DomainDN & "' WHERE objectCategory='User' AND sAMAccountName ='" & LoginName & "'"
End With
Set ADUser = ADCommand.Execute
With ADUser
EmailAd = !mail
End With
ADConn.Close
Set ADConn = Nothing
Set ADCommand = Nothing
Set ADUser = Nothing
End Function
However I can only get it to show my email. I cant get it to show a departments email or even a list of all emails in the active directory
Last edited by bignate; 12-06-2013 at 07:38 AM. Reason: I put in the wrong code
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'"
Just a wild guess. Maybe you can loop through with a variant. Something like.
Dim varAddress as variant
Dim strAnswer as string
for each varAddress in ADCommand.CommandText
strAnswer = varAddress
debug.print strAnswer
next
If it debugs a series if indexes then maybe.
dim intCount as integer
for intCount = 0 to ADCommand.CommandText
strAnswer = ADCommand.CommandText
debug.print strAnswer
next
Thanks. Where in my code would I put this?
After you assign .CommandText
Just after
.CommandText = "SELECT mail FROM 'LDAP://" & DomainDN & "' WHERE objectCategory='User' AND sAMAccountName ='" & LoginName & "'"
End With