Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Active Directory Integration

Status
Not open for further replies.

TTops

MIS
Sep 13, 2004
70
US
I have an Access 2007 form that retrieves its data from an Access 2007 table. I would like to save some of the form's fields (First Name, Last Name, Department, Address, etc.) to Active Directory as well. I know this can be done with VBA code, but I've never been tasked with this before. Can anyone point me in the right direction?

Thanks,
T-Tops
 
Since my original post, I have made some progress. I have written the following VBA code:

****************************************
Private Const RootPath As String = "LDAP://dc=MyOrganizationDomainName,dc=com"

Private Sub cmdGetADInfo_Click()
Const ADS_SCOPE_SUBTREE = 2

Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As ADODB.Recordset
Dim i As Integer

conn.Provider = "ADsDSOObject"
conn.Open "Active Directory Provider"
Set cmd.ActiveConnection = conn

Me.txtUserName.SetFocus

cmd.Properties("Page Size") = 1000
cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE
cmd.CommandText = "SELECT * FROM '" & RootPath & _
"' WHERE objectCategory='user' And sAMAccountName = '" & Me.txtUserName.Text & "'"

Set rs = cmd.Execute
rs.MoveFirst
i = 0
Do While Not rs.EOF
MsgBox "The field name is: " & rs.Fields(i).Name
MsgBox "The field value is: " & rs.Fields(i).Value
i = i + 1
rs.MoveNext
Loop
rs.Close

End Sub
****************************************

What this gives me is a single record with a single field from AD given a valid username from the txtUserName text box. The record set I get has a field name of "ADsPath" and a field value of "LDAP://CN=ValidUserName,OU=ValidContainerName,DC=MyOrganizationDomainName,DC=com". I need to get to the individual fields in AD that contain the user's mailing address fields, phone number fields, manager field, department field, etc. Any ideas?

Thanks,
T-Tops
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top