Help - Search - Members - Calendar
Full Version: LDAP Statement Syntax
MSFN Forums > Coding, Scripting and Servers > Programming (C++, Delphi, VB, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
swinomish
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

CODE
'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?

CODE
'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

crahak
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).

CODE
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)

swinomish
QUOTE (crahak @ Jul 11 2008, 11:46 AM) *
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).

CODE
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
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.