Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Excel, ADO, SharePoint - update 'person' type of field


Reply
 
Thread Tools Display Modes
  #1  
Old 07-22-2012, 11:42 AM
maciek_wroclaw maciek_wroclaw is offline
Newcomer
 
Join Date: Jul 2012
Posts: 2
Default 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
Reply With Quote
  #2  
Old 07-23-2012, 11:25 AM
maciek_wroclaw maciek_wroclaw is offline
Newcomer
 
Join Date: Jul 2012
Posts: 2
Default

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 ?
Reply With Quote
  #3  
Old 07-25-2012, 06:32 AM
TheRealTinTin's Avatar
TheRealTinTin TheRealTinTin is offline
Junior Contributor
 
Join Date: Nov 2008
Location: Glasgow, UK
Posts: 328
Default

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
Reply With Quote
Reply

Tags
ado, excel, sharepoint, update


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->