Provider error '80040e14'
One or more errors occurred during processing of command.
It is getting a SQL syntax error because part of the SQL statement looks
like this:
" AND sn = 'O'Hara' "
I have tried using double quotes but that gives a syntax error as well.
Below is a sample vbscript that uses SQL to search all users with a name of
Smith. If you can get it to work with O'Hara please let me know.
Thanks,
Roland
Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_SCOPE_SUBTREE = 2
Const adStateOpen = 1
Dim objDSE, objCon, objCmd, objRS, objUsr, strDNC
' Create Active Directory connection object
Set objCon = CreateObject("ADODB.Connection")
objCon.Provider = "ADsDSOObject"
objCon.Open "ADQuery"
' Create Active Directory command object
Set objCmd = CreateObject("ADODB.Command")
Set objCmd.ActiveConnection = objCon
' Create Active Directory SQL statement
Set objDSE = GetObject("LDAP://RootDSE")
strDNC = "LDAP://" & objDSE.Get("defaultNamingContext")
objCmd.CommandText = "SELECT ADsPath," & _
" userAccountControl" & _
" FROM '" & strDNC & "'" & _
" WHERE objectClass = 'user'" & _
" AND objectCategory = 'person'" & _
" AND sn = 'Smith'" & _
" ORDER BY displayName"
objCmd.Properties("searchscope") = ADS_SCOPE_SUBTREE
' Execute Active Directory SQL statement
Set objRS = objCmd.Execute
' Process active user accounts
While Not objRS.EOF
intUAC = objRS.Fields("userAccountControl")
If intUAC AND ADS_UF_ACCOUNTDISABLE Then
Else
strADsPath = objRS.Fields("ADsPath")
Set objUsr = GetObject(strAdsPath)
WScript.Echo objUsr.sAMAccountName & " " & objUsr.displayName
End If
objRS.MoveNext
Wend
' Destroy objects
Set objDSE = Nothing
Set objCon = Nothing
Set objCmd = Nothing
Set objRS = Nothing
Set objUsr = Nothing
" AND sn = ""O""Hare"""
I believe ' in VBScript (ASP) is represented by "".
Shahir
"Roland Smith" <rsm...@cvps.com> wrote in message
news:eWJHHJ0l...@TK2MSFTNGP09.phx.gbl...
"Shahir A. Ahang" <thisis...@thisisbsintrinsic.thisisbsnet> wrote in
message news:uNph640l...@tk2msftngp13.phx.gbl...
" AND sn = 'O''Hara' "
"Shahir A. Ahang" <thisis...@thisisbsintrinsic.thisisbsnet> wrote in
message news:uNph640l...@tk2msftngp13.phx.gbl...