Wednesday, October 5, 2011

Resolve error 800a01c2 when using the ADsContainer MoveHere method in VBscript

Many published scripts on the Internet suggest to use the MoveHere method as follows:
    intReturn = objOU.MoveHere(strADsPath, vbNullString)

This statement however throws the following error:


Even the Hey, Scripting Guy! Blog of the reference experts in VBScripting do so. Their script, however, doesn't throw an error as they set the following resume statement at the beginning of their script:
    On Error Resume Next
Don't do that! That is bad programming style!

The MoveHere method however returns the moved object and therefore the correct statement to use is:
    Set objCN = objOU.MoveHere(strADsPath, vbNullString)

And always remember what the scripting guys say: don’t burn down anyone’s house ;)

No comments:

Post a Comment