• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3150
  • Last Modified:

Is it possible to connect Active Directory in Microsoft Access?

Dear all experts,

Just wonder is it possible to connect the Active Directory by using ADSI under Microsoft Access.  As I know that in SQL Server, I can use the following query to connect to my AD

FROM "ldap://dc=bs,dc=brookes,dc=ac,dc=uk" WHERE
objectCategory = "Person" AND objectClass= "user"')

Now, I would like to know is it possible to implement it in Microsoft Access environment.

  • 2
1 Solution
Will something like this do you?

  Set objConnection = CreateObject("ADODB.Connection")
  Set objCommand = CreateObject("ADODB.Command")
  objConnection.Provider = "ADsDSOObject"
  objConnection.Open "Active Directory Provider"
  Set objCommand.ActiveConnection = objConnection

  objCommand.Properties("Page Size") = 1000
  objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

  objCommand.CommandText = _
      "SELECT Department, Title, sAMAccountName FROM 'LDAP://dc=corphq,dc=co,dc=uk' WHERE objectCategory='user' "
        '"AND Department !=''"
  Set objRecordset = objCommand.Execute

That was taken from http://www.tek-tips.com/viewthread.cfm?qid=1384174&page=7 .  I have used code similar to this (I don't have it anymore unfortunately!) in the past to get a list of usernames frmo AD for an Access database logon page...
towo2002Author Commented:
Dear Zenith63,

Thanks for your quick reply.  However, is it possible to implement it in "table" or "query"  way?  By using the script that you provided seems can only works on VBA form.  Since I would like to bind the AD objects to the access datagrid / combo box directly, it will be great if it can binds it in "query" or "table" format

Sorry I can't offer any more help with this, I just saw the question and remembered doing something similar so thought I'd post it.  There is quite a bit of info about this on Google though if you search for something like "Query Active Directory from Access VBA"

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now