Welcome to MSDN Blogs Sign in | Join | Help

Microsoft Access

The official blog of the Microsoft Access product team
Code to refresh SharePoint Link Tables

We have an internal Access Discussion alias that is used for by MS employees to get answers to their questions. Recently I saw a good question about how to refresh SharePoint lists. Here is the problem…

SharePoint lists that are linked to Access 2007 database files will not reflect structural changes to the lists in SharePoint.  Once someone changes list schema, you can continue to use the linked lists in Access for read-only purposes without even knowing that the list structure has changed.  You cannot, however, update the list data from within Access after a structure change unless you first refresh the list. 

Tom Beck wrote a handy little function to call refresh on all SharePoint link tables.

Sub RefreshSharePointLinks()    'DoCmd.Hourglass True
   Dim dbs As Database

   Set dbs = CurrentDb()

 

   For Each tbl In dbs.TableDefs

      If (Mid(tbl.Name, 1, 1) <> "~") And ((tbl.Attributes And dbAttachedTable) = dbAttachedTable) Then

         If Left(tbl.Name, 21) <> "User Information List" Then

            If Left(tbl.Connect, 3) = "WSS" Then

               sql = "SELECT * FROM [" & tbl.Name & "];"

               Set rst = dbs.OpenRecordset(sql, dbOpenDynaset)

               If Not rst.Updatable Then

                  DoCmd.SelectObject acTable, tbl.Name, True

                  DoCmd.RunCommand acCmdRefreshSharePointList

               End If

            End If

         End If

      End If

   Next

 

  'DoCmd.Hourglass False

 

End Sub

 

Next week I expect to tell you more about what Tom is doing with SharePoint.

Cheers!

Updated 10/20/2009 – Tom added a check for “WSS” in the connection string to handle other linked sources that are not from WSS and a check for updatability.

Posted: Wednesday, February 04, 2009 9:14 AM by Clint Covington

Comments

Derek said:

Hi Clint,

Good to see new posts on using Access with SharePoint.  I think these features also come in really handy if you need to manipulate, populate or update SharePoint lists, and I have a post on this here - http://workerthread.wordpress.com/2009/02/03/using-access-2007-to-update-sharepoint-lists/

Derek

# February 5, 2009 5:03 AM

JOel K said:

When i run this code, it creates duplicates of existing sharepoint links. I am not sure how to ensure i am refreshing a link versus creating a second link with the same name. (E.g. Employee and employee1)

Any suggestions?

# February 8, 2009 10:05 AM

tbeck said:

Joel K:  If you link a SharePoint list to Access and table (or link) already exists by that name, Access will add a number to the name; such as, in your case, a "1".  I can think of three ways this could be happening to you:  using the Access UI to create the link using the External Data feature, using the SharePoint list feature to export to Access, and using the TransferSharePointList method using VBA.  In each of these cases, you need consider whether an Access table (or link) by the same name already exists.  If it already exists, you may want to delete it first.  Otherwise, you can use the Refresh List option.  If you can share more information about the steps you're taking, I may be able to help you further.

# February 8, 2009 8:39 PM

JOel K said:

Thanks very much. Is there a VB way of eliminating a link reference without literally deleting the file on sharepoint. I have spent hours looking for that but to no avail.

IF there was i would remove teh link then reestablish.

# February 9, 2009 9:03 AM

tbeck said:

Joel K:  You may simply delete the link in Access.  I'm not yet aware of a way to delete a list in SharePoint from within Access.

I use this in VBA:

DoCmd.DeleteObject acTable, strTableName

You could be challenged, however, by Access during the deletion process that the object cannot be deleted because it is participating in one or more relationships.  If possible, you may want to consider deleting subordinate objects first.  I've found this to be the case with some list collections.

# February 9, 2009 10:27 AM

Albert Kallal said:

Anyone know what happens I re-link the connection between two different workspaces, or different SharePoint sites? Specific anyone know what happens to the local cache? If I re-link (or modify the GUID file name to where the link points), does the whole table get pulled down if I have local caching on?

I guess I am asking can I re-link between two different sets of “lists” on two different SharePoint sites? And, if so, can I “preserve” the table cache when I change the links to point to a different site?

This is partly a deployment issue, and a testing issue for me. In one scenario I want the customer to “change” to what location they are using. Thus I want to be able re-link to either “location”. I am testing this today, but in case anyone has more info on what happens to the cache (and can I preserve it), I am all ears. I am even willing to "copy" out the links to a local accDB file to keep the cache if that will speed up this process. So, in a sense, I am asking can one copy the links + cache to save them.

Albert D. Kallal

Edmonton, Alberta Canada

kallal@msn.com

# February 10, 2009 3:28 PM

Clint Covington said:

Albert--Unfortunately, I don't think this is a supported scenario. BTW - send me an email. I would love to hear how your SharePoint application is progressing.

# February 11, 2009 12:11 AM

Access Power Tips said:

If you’re linking an Access 2007 database to lists on a SharePoint server, you know that the links need

# February 13, 2009 11:28 AM

Josh Booker said:

Hi Clint,

Looking forward to your posts with more about what Tom is doing with SharePoint.

Keep up the good work.

Thanks,

Josh

# February 17, 2009 11:21 AM
New Comments to this post are disabled
Page view tracker