Jump to content

Recommended Posts

Posted

I am looking for a little help regarding syntax using variables in an LDAP statement.

Here is a piece of my code that works perfectly

'This section adds the new user to the Department Security Group
Set objGroup = GetObject ("LDAP:// cn=Bingo,OU=NLC Departments,dc=nlc,dc=com")
Set objUser = GetObject("LDAP:// cn=John Public,OU=NLC Users,dc=nlc,dc=com")
objGroup.add(objUser.ADsPath)

I have two variables that are captured in my form .. strDepartment & strUser that I am having problems inserting into the above LDAP statement in the CN field. The strDepartment Variable can be chosen from a drop down list that reads from my AD. There can be 12 choices, I used CN=Bingo as a test example, any of the other 11 work as well.

When I try it like this I get object not found on server.. I have used the & symbol and Quotes “” in various spots but cannot seen to find the correct syntax. any ideas?

'This section adds the user to the Department Security Group
Set objGroup = GetObject ("LDAP:// cn=strDepartment,OU=NLC Departments,dc=nlc,dc=com")
Set objUser = GetObject("LDAP:// cn=strUser,OU=NLC Users,dc=nlc,dc=com")
objGroup.add(objUser.ADsPath)

Thanks

Sam


Posted

You can't just use variable names in the middle of a string. You have to close the string, add your variable, then add the last part (each part must be properly enclosed in quotes).

Set objGroup = GetObject ("LDAP://cn=" & strDepartment & ",OU=NLC Departments,dc=nlc,dc=com") 
Set objUser = GetObject("LDAP://cn=" & strUser & ",OU=NLC Users,dc=nlc,dc=com")
objGroup.add(objUser.ADsPath)

Posted
You can't just use variable names in the middle of a string. You have to close the string, add your variable, then add the last part (each part must be properly enclosed in quotes).

Set objGroup = GetObject ("LDAP://cn=" & strDepartment & ",OU=NLC Departments,dc=nlc,dc=com") 
Set objUser = GetObject("LDAP://cn=" & strUser & ",OU=NLC Users,dc=nlc,dc=com")
objGroup.add(objUser.ADsPath)

Thanks , it works perfectly now...

I don't know why I did not see that before.. just looking at it to long I guess

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...