Solved

Updating Active Direcory using VBs

Posted on 2001-06-28
8
351 Views
Last Modified: 2008-02-01
Hello,

I am trying to update some fields within our Active Directory using VBs.

I am using the following script from miscrosoft as an example:
_____
'Replacing department for all users in OU=sales
Set con = Server.CreateObject("ADODB.Connection")
con.Provider = "ADsDSOObject"
 
Set command = CreateObject("ADODB.Command")
Set command.ActiveConnection = con
 
command.CommandText =
"SELECT AdsPath, cn, FROM '<LDAP://OU=Sales,DC=ArcadiaBay,DC=com>'
 WHERE objectClass = 'user'"
 
Com.Properties("searchscope") = ADS_SCOPE_ONELEVEL
Set rs = Com.Execute
While Not rs.EOF
    Set usr = GetObject(rs.Fields('AdsPath').Value)
    usr.Put "department", "1001"
    usr.SetInfo
    rs.MoveNext
Wend
____

My version is this:
____
Set con = Server.CreateObject("ADODB.Connection")
con.Provider = "ADsDSOObject"

Set command = CreateObject("ADODB.Command")
Set comand.ActiveConnection = con

command.CommandText = "SELECT ADsPath, cn, FROM '<LDAP://CN=v10203,CN=Users,DC=org,DC=local>' WHERE ObjectClass = 'user'"

Com.Properties("searchscope") = ADS_SCOPE_ONELEVEL
Set rs = Com.Execute

While Not rs.EOF
     Set usr = GetObject(rs.fields('AdsPath').Value)
     usr.Put "mail", "aaa@bbb.com"
     usr.Put "manager", "CN=V10316,CN=Users,DC=org,DC=local"
     usr.SetInfo
     rs.MoveNext
Wend
___
I get an error on the followong line:

Set usr = GetObject(rs.fields('AdsPath').Value)

Character 32 saying "Syntax Error 800A03EA"

Can anybody help me with this please?
0
Comment
Question by:ironeye
  • 4
  • 3
8 Comments
 
LVL 11

Accepted Solution

by:
Otana earned 100 total points
ID: 6234445
Shouldn't the single quotes be double quotes?
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6234471
Either that or it is being strangely case specific as the Name of the field returned is ADsPath not AdsPath. But I would go with the double qoutes first myself.
0
 

Author Comment

by:ironeye
ID: 6234508
Thanks,

I changed the single quotes into double ones and I got a little further.

First I had to change Server.CreateObject into CreateObject, and now I get the following error:

Operation is not allowed on an object referencing a closed or invalid connection. Source: ADODB.Command

Suggestions?
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 11

Expert Comment

by:Otana
ID: 6234523
Set command = CreateObject("ADODB.Command")
Set command.ActiveConnection = con

when you execute these lines, make sure con is already/still opened
0
 

Author Comment

by:ironeye
ID: 6234538
Is that just by saying con.open?
0
 
LVL 11

Expert Comment

by:Otana
ID: 6234548
I think so. You have to make sure though that all your required properties are set, like which database you're connecting on etc.

I believe it's also possible to put these properties in the connectionstring
0
 

Author Comment

by:ironeye
ID: 6234549
I'll go to the testing area and just try! I'll get back.
0
 

Author Comment

by:ironeye
ID: 6251996
it took a while, but i got it going now.

Thanks.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

806 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question