Appending some data of Active Directory to access/SQL table and #Deleted values

I

Ivan

Hello,

to populate an access table tblActiveDirectory with some data about users
from Active Directory Service I prepared mayself the folowing function:

--------------------------------------------------------
Public Function MakeTableUsersOfAD()

Dim cnnAD As ADODB.Connection
Dim cnnAcc As ADODB.Connection
Dim cmdAD As ADODB.Command
Dim cmdAcc As ADODB.Command
Dim rstAD As ADODB.Recordset

'Using delete query qdelTblActiveDirectory first delete all records from
the access table tblActiveDirectory

DoCmd.SetWarnings False
DoCmd.OpenQuery "qdelTblActiveDirectory", acViewNormal, acEdit
DoCmd.SetWarnings True

'Open some data about users of Active Directoryja as a new recordset

Set cnnAD = New ADODB.Connection
cnnAD.ConnectionString = "Provider = ADSDSOObject;"
cnnAD.Open

Set cmdAD = New ADODB.Command
cmdAD.ActiveConnection = cnnAD
cmdAD.CommandText = "SELECT name, userPrincipalname, givenName,
displayName, sn, sAMAccountName, mail " & _
"FROM 'LDAP://MyDomainServer'" & _
"WHERE objectCategory='Person'" & _
"AND objectClass='user'"

Set rstAD = New ADODB.Recordset
Set rstAD = cmdAD.Execute

'Every record from Active Directoryja append separately into the table
tblActiveDirectory

Set cnnAcc = CurrentProject.Connection
Set cmdAcc = New ADODB.Command
Set cmdAcc.ActiveConnection = cnnAcc
cmdAcc.CommandType = adCmdText

rstAD.MoveFirst

While Not rstAD.EOF
cmdAcc.CommandText = "INSERT INTO tblActiveDirectory " & _
"(name, userPrincipalname, givenName, displayName,
sn, sAMAccountName, mail) " & _
"VALUES ('" & _
Trim(rstAD.Fields("name")) & "', '" & _
Trim(rstAD.Fields("userPrincipalname")) & "', '" & _
Trim(rstAD.Fields("givenName")) & "', '" & _
Trim(rstAD.Fields("displayName")) & "', '" & _
Trim(rstAD.Fields("sn")) & "', '" & _
Trim(rstAD.Fields("sAMAccountName")) & "', '" & _
Trim(rstAD.Fields("mail")) & _
"')"
cmdAcc.Execute
rstAD.MoveNext
Wend

rstAD.Close

Set rstAD = Nothing
Set cmdAD = Nothing
Set cnnAD = Nothing
Set cmdAcc = Nothing
Set cnnAcc = Nothing

End Function
--------------------------------------------------------

The above function run successfully until I transfered the table
tblActiveDirectory (it has an "autonumber" primary key) to my SQL server.
In the access .accdb file I have now an ODBC link to the table
tblActiveDirectory which lives on the SQL server and it seems that as the
function now runs without the problems but when I open the linked table
tblActiveDirectory in the access aplication I get all fields populated with
#Deleted values. It is interesting that if I open the table with SQL Server
Enterprise Manager then I can see all the rows normal. And if I want in the
access aplication to delete the rows of tblActiveDirectory with the delete
query I get the message that "Microsoft Office Access can't delete ... ...
records due to lock violations". Why? My functioh has already finished his
task and nobody else should hold the table!?

Any hint will be welcome

Ivan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top