I cannt ADSI search scrpting going? -help
Hi;
I am having abit of trouble with ADSI scripting, Hope someone can help
me out in here, First, let me explain my logic in here:
I have a flat file that contain employee'ID, telephone number
etc..imported into local access database.
then I am writing VB exe file to automate upload those data into the
Active Directory.
So far my exe file can get data from the access database, but running
error with the ADSI script when dubuging into
"strADsPath = objRecordSet.Fields("ADsPath")" line. It shows error with
"runtime error3021, Either BOF or EOF is true or the
current record has been deleted, Request current operations requeires a
current record."
I dont know what happen with my logic, if I run that ADSI script in
separate exe file, it is working fine, however, if I put
them all together, it turns out to give me the error. Anyone can help
me, thanks in advance. below is my code
Option Explicit
Sub Main()
Call Upload_User_Attribute
End Sub
Public Function Upload_User_Attribute()
Dim conn As ADODB.connection
Dim rs As ADODB.Recordset
Dim sConnString As String
Dim strPN As String
Dim strLastSSN As String, strFirstName As String, strLastName As String
Dim strSQL As String
Dim FirstName, LastName, strAccountID
Dim CHILD_DOMAIN_ADDRESS
Dim sAMAccountName
Dim objConn, strQuery, objRecordSet, objUser, strADsPath
Dim strDisplayTelephoneNumber
CHILD_DOMAIN_ADDRESS = "dc=dell,dc=DELLROOT,dc=org"
'Create the connection
Set conn = CreateObject("ADODB.Connection")
sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Deploy08022005\data\user_attribute.mdb"
conn.Open sConnString
'Create the Recordset
Set rs = CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM Sap_flat"
rs.Open strSQL, conn, adOpenForwardOnly, adLockReadOnly
'Check for records
If Not rs.EOF Then
'Loop through all records
Do Until rs.EOF
strLastSSN = rs.Fields("LastSSN").Value & ""
strFirstName = rs.Fields("FirstName").Value & ""
strLastName = rs.Fields("LastName").Value & ""
'Compile AccountID
FirstName = Left(strFirstName, 1)
LastName = Left(strLastName, 7)
strAccountID = FirstName & LastName & strLastSSN
'Search AD AccountName
'strAccountID = "trandolp8441"
strDisplayTelephoneNumber = "314-345-2427"
Set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOOBJECT"
objConn.Open
strQuery = "SELECT ADsPath FROM 'LDAP://DC=child,DC=dev,DC=org' WHERE
objectclass='User' and SAMAccountName = '" & strAccountID & "'"
Set objRecordSet = objConn.Execute(strQuery)
strADsPath = objRecordSet.Fields("ADsPath")--------------------->this
is why I get error when is debugging
Set objUser = GetObject(strADsPath)
objUser.Put "telephoneNumber", CStr(strDisplayTelephoneNumber)
objUser.SetInfo
rs.MoveNext
Loop
Else
MsgBox "No records found"
End If
'Cleanup
If rs.State = adStateOpen Then rs.Close
Set rs = Nothing
If conn.State = adStateOpen Then conn.Close
Set conn = Nothing
End Function
date: 17 Aug 2005 11:20:24 -0700
author: weiwei