 |
 |

07-22-2012, 11:42 AM
|
|
Newcomer
|
|
Join Date: Jul 2012
Posts: 2
|
|
Excel, ADO, SharePoint - update 'person' type of field
|
Hello,
I am using ADO to retrieve data from SharePoint lists. This, is working quite fine. The problem appears when I am trying to use ADO routine to 'update' some fields in SharePoint list.
The worst thing is, that Excel is not giving me any error messages - it's just crashes and showing 'not responding'..
I've noticed that when a 'number' type of field is being updated - routine is working very well. But when I am trying to update 'person' type of field - it crashes every time.
I've tried in many ways to make it work.. using recordset .update method, command.execute - also tried with different options like adClientSide, adServerSide..
No matter of code I have - excel always crashes. I've even tried to accomplish that in MS Access - but still with the same result.
Here is the code I have so far, please if you have any suggestions that I can check/test I will highly appreciate that!
Code:
Sub Test()
Dim rsCon As ADODB.Connection
Dim rsData As ADODB.Recordset
Dim rsComm As ADODB.Command
Dim TableName As String
Dim szConnect As String
Dim szSql As String
Dim Rng As Range
Dim cell As Range
Dim LastRow As Long
TableName = "Balance"
If Val(Application.Version) < 12 Then
szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;WSS;" & _
"IMEX=2;" & _
"RetrieveIds=Yes;" & _
"DATABASE=" & Database & ";" & _
"LIST=" & Balance & ";"
Else
szConnect = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;" & _
"IMEX=2;" & _
"RetrieveIds=Yes;" & _
"DATABASE=" & Database & ";" & _
"LIST=" & Balance & ";"
End If
Set rsCon = New ADODB.Connection
Set rsComm = New ADODB.Command
LastRow = wksUpdateManagers.Range("A" & wksUpdateManagers.Rows.Count).End(xlUp).Row
Set Rng = wksUpdateManagers.Range("F9:F" & LastRow)
For Each cell In Rng
szSql = "Update " & TableName & " Set SuperVisorName = " & cell.Offset(0, 1).Value & " where FullName = " & cell.Value
'szsql = Update Balance set SuperVisorName = 9 where FullName = 1
'where 9 and 1 are IDs from UserInfo table on SharePoint
rsCon.ConnectionTimeout = 30 'this is not working at all in my case..
rsCon.Mode = adModeReadWrite
rsCon.Open (szConnect)
rsCon.CursorLocation = adUseClient
With rsComm
Set .ActiveConnection = rsCon
.CommandText = szSql
.CommandTimeout = 30
.Execute 'Here is the line where Excel crashes
'when I used the recordset the excel crashes at line:
'rst.fields("PersonField").value = 5
'where 5 is an ID of person in UserInfo table on SharePoint.
'when I swithed cursor location from adUseServer from adUseClient then Excel crashes on line:
'rst.update
End With
rsCon.Close
Next cell
rsData.Close
rsCon.Close
Set rsData = Nothing
Set rsCon = Nothing
End Sub
|
|

07-23-2012, 11:25 AM
|
|
Newcomer
|
|
Join Date: Jul 2012
Posts: 2
|
|
Hi all,
I've been testing this all day long. I came up with two new things:
1. sometimes above code works! It turned out that for some values in 'person or group' field it works and for the others - it doesn't. I can't find any rule which may give some light why it is happening.
2. Sometimes when I was kililng the Excel I was able to see error message. It was saying:
"Data provider or other service returned an E_FAIL status"
Not sure if that helps, because as I said for some records it works, for some - not.
Do you have any tip, suggestion, idea, even random words  which I can use to figure it out ?
|
|

07-25-2012, 06:32 AM
|
 |
Junior Contributor
|
|
Join Date: Nov 2008
Location: Glasgow, UK
Posts: 328
|
|
|
Hi and welcome to XVBT.
I don't normally use ADO so cannot claim to know about the issue you are having. But if you are simply updating an existing record then this is fairly simple. There are a lot of similarities between ADO and DAO, which I tend to use.
Scimming through your code I notice a comment that says when you use recordset instead, it crashes. The line 'rst.fields("PersonField").value = 5' is wrong, take away the .value and it should work. There are no parameters of database fields. This shouldn't cause a crash but I guess it could. There are loads of tutorials on the web and posts on here that tell you how to update records on a database using an ADO connection so if you get stuck I would try doing a search using something like ADO update record.
If I get time I'll whip something up quickly using ADO but it's been so long I can't remember off the top of my head. Hopefully an expert will come on and perhaps be of more use.
|
__________________
Artificial Intelligence is no match for natural stupidity
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|