Transfer SharePoint List Object Model

Aside from being able to import data into Access from the SharePoint entry point, a developer can also leverage some Access Object Model functions available for importing data from SharePoint. Specifically, the TransferSharePointList method allows a developer to either import or link to a SharePoint list programmatically. TransferSharePointList is a method of the DoCmd class, which is a member of the Application object. TransferSharePointList takes up to six arguments, three of which are required. The following table describes each of these arguments.

Parameter

Description

TransferType

Requires a member of the enumeration type AcShare-PointListTransferType. Two options are available: acImportSharePointList and acLinkSharePointList.

SiteAddress

The full URL path to the SharePoint site. This parameter is required.

ListID

The Name or the GUID of the list to be transferred. This parameter is required.

ViewID

The GUID of the view that should be imported. This means that imported data can be pre-filtered by a specific list view on SharePoint before pulling the data into Access. This parameter is optional and not available for when the acImportSharePointList option is chosen for the Transfer type. If not specified, all of the fields on the SharePoint site will be retrieved.

TableName

The name of the new linked table in the database. This parameter is optional and not available for when the acImportSharePointList option is chosen for the Transfer type. If not specified, the name of the SharePoint list will be used for the new table in the database.

GetLookupDisplayValues

When false, any lookup fields will contain the IDs to the list to which the lookup is tied. When True, the actual display values will be imported. This parameter is optional and not available for when the acImportSharePointList option is chosen for the Transfer type.

Importing SharePoint data into an Access database is extremely easy to do. Just remember that when importing data, only the first three parameters (the non-optional parameters) to the TransferSharePointList method can be supplied; otherwise, an error message is raised when the code runs. Here's an example of a simple subroutine for importing a list from SharePoint:

Sub ImportSharePointList()

' Call TransferSharePointList to import the data Application.DoCmd.TransferSharePointList _

acLinkSharePointList, _

"http://MySharePointSite/",

"Tasks"

End Sub

Writing code for a single import operation may not be cost effective or the easier way for a user to import SharePoint lists into a database. In addition to the entry points for creating an import table in Access from the SharePoint site, there is also a user interface for importing a SharePoint list from within the Access UI.

+1 0

Post a comment