Someone asked a question on the UK SharePoint User Group Forums about moving Access data to SharePoint lists, so I thought I would illustrate some of the Access 2007 features you can use with SharePoint. Before starting, please note – SharePoint is not a relational database system, so don’t try to use it for full-blown relational database applications!!! Having said that, it does work well for many smaller list-management applications for which you might have used Access or Excel, and I guess it’s possible (pure speculation here) that by the time we start hearing more about SharePoint 14 and Office 14, SharePoint and Access may be getting even closer together.
So, lets look at a SharePoint scenario:
I have a SharePoint list, in this case for contacts, and it includes a “Department” column. This list may have been imported from Excel or Access, and the department column is currently a single line of text:
So I create a separate custom Department list with a Title column like so:
But at this stage, it’s not possible to edit the Contacts Department column from text to lookup, as you will see if you try to edit the Column properties:
So instead, I am going to create a new Department column of type Lookup, and use Access to do the updating work. First, we RENAME the existing department as OldDepartment, then create a new column of type Lookup to store the lookup values from the Department list:
Now at the moment the Department list doesn’t contain any values, so we’ll also populate that list from a set of unique departments in the contact list. So fire up Access 2007 and create a new blank database. Next we link the contacts and department lists from SharePoint. Do this by selecting the External Data tab and clicking on SharePoint list:
The Get External Data – SharePoint site wizard starts up:
Enter the url of the site containing the Contacts and Department lists, and be sure to select “Link to the data source by creating a linked table” option. Then check the lists you want to link to and click OK:
Now we’ll populate the Departments list. from the Create tab in Access select “Query Design”:
Add the Contacts list to the Query pane and drag OldDepartment into the grid:
We want a unique list of departments, so open the query property sheet, and set Unique Values to “Yes”:
This will give us our unique list of departments, and we want to append these to our empty Department list, so change the query type to Append:
Select Department as the table you want to append to:
Then select Title as the field you want to append to:
Now run the query. Access will tell you how many records will be appended, and warn that the action cannot be undone. Once it runs, you will have a unique set of departments:
Now we can update our department lookup column in Contacts. Under the covers, the lookup will be stored as a number in the Contact list, and match to the ID column of a row in the Department list. So, in effect, we want to create a query which says “look up the Department ID by matching Contacts oldDepartment with Title in Department, and add the Looked up Department ID to the Department column in Contacts”. So we create a new Update query to do this. If we create a query from Contacts and department, it will default to joining Contacts.Department to Department.ID:
But we don’t want this, so delete the join, and instead drag Department.Title to join to Contacts.OldCompany like so:
We need to change the query type to an Update Query:
And we will update the Contacts.Department to the value of matching Department ID:
Now we can run the query, and when it completes, our lookup values will be updated:
We can now delete the OldDepartment column from our SharePoint list, and we will have available Department values in the correct lookup column:
And that’s it!
February 4, 2009 at 2:11 pm |
[...] Using Access 2007 To Update SharePoint Lists (WorkerThreadBlog)Someone asked a question on the UK SharePoint User Group Forums about moving Access data to SharePoint lists, so I thought I would illustrate some of the Access 2007 features you can use with SharePoint. Before starting, please note – SharePoint is not a relational database system, so don’t try to use it for full-blown relational database applications!!! Having said that, it does work well for many smaller list-management applications for which you might have used Access or Excel, and I guess it’s possible (pure speculation here) that by the time we start hearing more about SharePoint 14 and Office 14, SharePoint and Access may be getting even closer together. [...]
February 4, 2009 at 8:04 pm |
Hi Derek,
Nice tricks.
So Many Thanks.
February 20, 2009 at 11:03 pm |
I used your recommendations and worked excellent.
But I liked to know how can I do to update a field with the property “Allow multiple values” is activated.
Thanks in advance.
February 21, 2009 at 2:12 pm |
Hi Oscar,
Do you mean how do you get the unique values out of a “multiple value” list? You could try creating an Access query and use the .Value field in the SELECT. Here is a Microsoft Article which describes this.
Derek
March 16, 2009 at 6:46 pm |
How can administrator’s or designer’s remove external (DEAD) datalinks for issues with permissions.
March 17, 2009 at 7:11 pm |
@MSTech Not quite sure what you mean – are you referring to linked SharePoint lists in an Access database? Can you give me a bit more info?
April 22, 2009 at 6:09 pm |
Thanks for the article on how to create lookups from data orgininating from Access. I do not have Access 2007 but rather, Access 2003. Will I be able to accomplish the same thing through Access 2003?
In Access, I tried using my Contacts table which was performing a Lookup on ContactType to the ContactType table. I then exported the Contacts table to SharePoint (WSS 3.0) and saw that the export did not bring over the ContactType table when I exported the Contacts table. I thought it might do that in that the ContactType column in the Contacts table was performing a lookup to the ContactsType table based on ContactsType.ID. Instead it exported only the number (ID) from the Contacts table to SharePoint.
Is there no easier way to do this without having to go through all these steps whenever a table lookup occurs?
Thank you.
April 23, 2009 at 12:34 pm |
Hi Larry,
Well, Access 2003 isn’t so aware of SharePoint lists as 2007 is. But I do believe you can use Get External Data/Link Tables to link to SharePoint lists in 2003, and I guess after that you could try to create the queries I describe above.
If you just need to use Access to make the list updates I describe as a one-off exercise, I guess you could install the time-limited evaluation version of Office or Access 2007 and do the work from there
.
Derek
April 27, 2009 at 3:28 pm |
Thanks for the good information. I have a question that has not been pointed yet I think. Is there a way to verify that Access 2007 is compatible with Sharepoint 2003 because our Sharepoint server is still running the 2003 version. I did some tests and I can’t update the sharepoint list from Access 2007 as proposed. I was wondering if it was user-right problem or just a software compatibility issue.
Thanks in advance for an answer,
April 27, 2009 at 3:33 pm |
qctester,
To get a bit more info on compatibility I would take a look at the Microsoft’s Fair, Good, Better, Best document which you can download from here.
Derek
September 9, 2009 at 3:39 am |
Thanks for a good post, there is so much potential in the SP-Access 2007 integration that we need much more of this type of information.
I’ve run into a problem that I wonder if you may have seen or heard of before. I have several lists from a MOSS 2007 site as linked tables in an Access 2007 db. I used to be able to open and work with all of them through the Access GUI, but lately one of the lists won’t open, be refreshed or at all participate in any commands from the Access frontend. It works a charm through the SP web interface.
The error messages I’m getting are
“Cannot connect to the Sharepoint site ’site name’. Try again later.”
and
“Microsoft Access can’t open the table in Datasheet view.”
I’ve troubleshot from every angle I can think of to no avail. Any ideas?
September 11, 2009 at 9:06 am |
Hi Robert
I agree with you, Access 2007 and SharePoint work really well together, and a lot of SharePoint users haven’t exploited it fully.
Regarding your problem with one SP list, I haven’t had this problem myself although doing a quick web search I can see one or two others reporting it. I guess you have tried deleting the link and re-linking?
The fact that it was working once and is not now (and that it is only one list) suggests that something has changed somewhere. Maybe something related to structure or permissions on the SP list?
Derek
September 13, 2009 at 8:06 pm |
Yeah I’ve tried deleting and relinking. I’ve also tried recreating the Access database and table linkage in all possible ways. I’ve tested it on different machines and on different user accounts to no avail. It shouldn’t be a permissions issue as I am able to work with the list freely in the Sharepoint web GUI.
I have added columns to the list since the point in time when it was working. I’m having a hard time troubleshooting individual columns though as Access will not open the table at all, nor include any single column from the table in a query. I can view and edit all columns in Datasheet view through the Sharepoint web GUI, though, so no clues there.
Searching the web extensively I have only found a few other people with the same issue and no one with a solution. Would really appreciate any tips or more information from anyone on this issue.
September 14, 2009 at 8:15 am |
Hi Robert
Clutching at straws here, but I wonder if it’s something specific in the SP list? Have you tried saving the list as a template including content from within SharePoint, creating a new list from the template then seeing if Access can connect to it?
Also maybe it’s worth trying to connect to the list from something else that uses the SP Web service to get data, to . If you search around there are free downloads available like the Stramit CAML viewer that should be able to connect/query the list. Would be interesting to see if you can any problems with these.
Derek
September 14, 2009 at 10:37 pm
Thanks for the tips, I’ll give them a go and see how we go. I’ll gladly clutch at any straw at this point.
October 27, 2009 at 7:15 pm |
So my above issue mysteriously disappeared after I had recreated my Access database a few times. Not at all reassuring but I’ll take it…
Next issue I have run into has to do with lookup columns. One of my list uses about five lookup columns, all connected on ID. When I run update queries on the list, I sometimes get an error saying that a record could not be saved because the value in one of the lookup columns was not valid. Looking closer at the list this is caused by the value zero (0) in lookup columns. It seems that the value of a lookup column is set to zero if the item is edited through the default EditForm.aspx and left blank. Has anyone else run into this and do you know if there’s any way of avoiding it (other than not using the default EditForm.aspx page of course)?
October 28, 2009 at 9:25 am |
Hi again Robert
Could you make the lookup column required to ensure it isn’t left empty?
October 28, 2009 at 6:40 pm
The thought has crossed my mind, but some of the lookup columns are used exclusively by custom workflows and assigning a value to the columns would indicate that a process has been applied to the list item. I would really want to keep null values unless there is a real value, and this is not a problem most of the time. It is only when I edit an item using the default EditForm.aspx page and leave the lookup field blank that it is set to 0.
November 23, 2009 at 10:39 pm |
Robert, the workaround would be to run update queries replacing the 0’s with Nulls before you run your forms/ other update queries.
This will require a number of queries because you have to query for every permutation of “0″ fields, working down from 5 fields to 1, because if you do them one at a time, it won’t let you save the record.
Alternatively, you could write a VB module which would go through the table and replace all 0’s with Nulls for any number of columns. Then, just run that code before you open any related forms or run update queries.
November 23, 2009 at 7:08 pm |
Thanks for the post! I’m having the exact same problem but haven’t diagnosed it until your comment. I can now see that SharePoint (2007) sets the lookup values to “0″ if the user chooses “(None)”, which then causes errors in Access 2007. My fields aren’t used by SharePoint workflows or anything, so I should be able to require values and supply a “null” lookup or something, but it’s very annoying. Please post back if you find a fix.
December 2, 2009 at 5:09 pm |
This article helped me SO much. The only thing I found a problem with was if the field you are replacing is the main “title” field, it won’t let you delete it afterwards. I just hid it from the view, but it still shows up when the user clicks “new”. However, they can add through the datasheet without any problem. Any ideas of how to get around this would be appreciated. I have SP Designer, but didn’t want to modify the form if I didn’t have to.
December 2, 2009 at 10:22 pm |
Hi Beth,
If you are able to switch on “allow management of content types” in your list you can then change the properties of the Title column so that it is hidden (will not appear in forms) there is an easy to follow blog post on how to do this here http://www.dlocc.com/articles/how-to-remove-title-column-from-sharepoint-list/
Derek