Joe3Rings
asked on
Access 2007 using Active directory for domain groups
Does anyone know how to get groups from AD available to my Access 2007 App? I have seen a few bits of code but can't get anything to work. I think it is to do with VBA references also. It could also be that while I have some of the code I don't know how to call the code. An example of code can be found here but how do I get it to run?
http://www.microsoft.com/technet/technetmag/issues/2006/03/ScriptingGuy/default.aspx
or http://www.adminscripteditor.com/scriptlibrary/view.asp?id=254
http://www.microsoft.com/technet/technetmag/issues/2006/03/ScriptingGuy/default.aspx
or http://www.adminscripteditor.com/scriptlibrary/view.asp?id=254
ASKER
Thanks for that but I get a runtime error. I have added the MS Scripting Runtime library. Screen shot attached. I'm calling the function from the imediate window. This would work for me if I could feed it the username and group. I am right is saying I could change the function to accept ther two variables?
Thanks
Error.doc
Thanks
Error.doc
You need a reference to the ADO library - in my Access 2003 setup it's
Microsoft ActiveX Data Objects 2.1 Library
To pass the variables to the function do this - I am assuming you want to pass the domain name and the group
Public Function TestADGroups(strDomain As String, strGroup As String)
On Error GoTo Err_TestADGroups
Dim objGroup As Object, objUser As Object, objFSO As Object
Dim objFile As Object, RootDSE As Object, objConnection As Object
Dim objCommand As Object
Dim objRecordset As ADODB.Recordset
'Dim strDomain As String, strGroup As String
Dim strUserName As String, strSearchRoot As String
Dim strQueryText As String, strFName As String, strLName As String
If you want to pass the username and retrun all group memberships for that user, like in one of the links you provided, you'll need to make minor modification to the code.
OM Gang
Microsoft ActiveX Data Objects 2.1 Library
To pass the variables to the function do this - I am assuming you want to pass the domain name and the group
Public Function TestADGroups(strDomain As String, strGroup As String)
On Error GoTo Err_TestADGroups
Dim objGroup As Object, objUser As Object, objFSO As Object
Dim objFile As Object, RootDSE As Object, objConnection As Object
Dim objCommand As Object
Dim objRecordset As ADODB.Recordset
'Dim strDomain As String, strGroup As String
Dim strUserName As String, strSearchRoot As String
Dim strQueryText As String, strFName As String, strLName As String
If you want to pass the username and retrun all group memberships for that user, like in one of the links you provided, you'll need to make minor modification to the code.
OM Gang
ASKER
What I'm really trying to do is give it the username and group so I can set up a menu dependant on what group the user is in.
ASKER
I now get this error, Automation error The network path was not found.
Error.doc
Error.doc
On what line is this error occuring?
OM Gang
OM Gang
ASKER
It doesn't say an error line or stop on a row. It just shows the pop up wondow. See screen shoot. Thanks in advance for all your help.
Error.doc
Error.doc
ASKER
This is a screen shot of my current references
references.doc
references.doc
Put a break-point in your code, like on
strDomain = "....."
Now when you call the function the code will stop on that line and allow you to step through the code one line at a time.
OM Gang
strDomain = "....."
Now when you call the function the code will stop on that line and allow you to step through the code one line at a time.
OM Gang
ASKER
I have added what I think is a breakpoint, I'm then pushing f5 to continue. It stops first time at the break point then goes to the msg box? See the screen shot attached to last comment.
In the VB editor, click the View menu and then Toolbars. Click to show the debug toolbar. On this toolbar you have some buttons for stepping through the code.
Launch your function. When the code breaks at the break-point you have inserted, click the 'Step Into' toolbar button to step through the code line-by-line. Move your mouse pointer over the toolbar buttons to see which one is 'Step Into'
OM Gang
Launch your function. When the code breaks at the break-point you have inserted, click the 'Step Into' toolbar button to step through the code line-by-line. Move your mouse pointer over the toolbar buttons to see which one is 'Step Into'
OM Gang
ASKER
Okay, it stops at
strGroup = "joebyrne"
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
MsgBox Err.Number & ", " & Err.Description, , "Error"
Then I get the error msg box?
strGroup = "joebyrne"
Set objFSO = CreateObject("Scripting.Fi
Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
MsgBox Err.Number & ", " & Err.Description, , "Error"
Then I get the error msg box?
Is 'joebyrne' really the name of one of your AD groups? Looks like a user to me.
Try this one out instead. I just tested it and it works for what you want
OM Gang
Try this one out instead. I just tested it and it works for what you want
OM Gang
Public Function TestADGroups2(strUserName As String)
On Error GoTo Err_TestADGroups2
Dim objUser As Object, objGroup As Object
Dim RootDSE As Object
Dim strSearchRoot As String
Dim colGroups As Object
Set RootDSE = GetObject("LDAP://RootDSE")
strSearchRoot = RootDSE.Get("defaultNamingContext")
Set objUser = GetObject("LDAP://CN=" & strUserName & ",OU=OUName," & strSearchRoot)
Set colGroups = objUser.Groups
For Each objGroup In colGroups
Debug.Print objGroup.CN
Next
Exit_TestADGroups2:
Set RootDSE = Nothing
Set objGroup = Nothing
Set colGroups = Nothing
Set objUser = Nothing
Exit Function
Err_TestADGroups2:
MsgBox Err.Number & ", " & Err.Description, , "Error"
Resume Exit_TestADGroups2
End Function
ASKER
Sorry that was my mistake but I still get an error. See attached screen shot. Am I doing it correctly by using the imediate window to check.
screen-shot.doc
screen-shot.doc
You left OU=OUName in the code. You need to change that to whatever the name of the OU is, or names of the OU's are, in your situation, i.e. in my environment it's something like
Set objUser = GetObject("LDAP://CN=" & strUserName & ",OU=Users,OU=Accounting," & strSearchRoot)
OM Gang
Set objUser = GetObject("LDAP://CN=" & strUserName & ",OU=Users,OU=Accounting,"
OM Gang
you need what's called the DN, or distinguished name, of the AD object you want to bind to
Set objUser = GetObject("LDAP://CN=OM Gang,OU=Users,OU=Puter Fixers,DC=SillyDomain,DC=c om)
This refers to the user object OM Gang
in the container (organizational unit) Users
in the container (organizational unit) Puter Fixers
in the domain SillyDomain.com
OM Gang
Set objUser = GetObject("LDAP://CN=OM Gang,OU=Users,OU=Puter Fixers,DC=SillyDomain,DC=c
This refers to the user object OM Gang
in the container (organizational unit) Users
in the container (organizational unit) Puter Fixers
in the domain SillyDomain.com
OM Gang
obviously, in my sample code, strUserName is used to pass the user name and strSearchRoot passes the DC entries.
OM Gang
OM Gang
ASKER
Sorry I am still missing something, I have a OU called SBSUsers, a domain called jbit.local and a user called joebyrne. See screen shot again, it says object does not exist.
screen-shot.doc
screen-shot.doc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks :)
OM Gang
Open in new window