Consuming Excel Data using InfoPath Database Data Connections

InfoPath data connections can be one of the most powerful features of the product.  However, sometimes the out-of-box support for various data sources just doesn't seem to cut it when you get out into the field.  How in the world can I get data from an Excel spreadsheet  into my InfoPath form?  A typical response might include externally automating Excel via COM or the managed PIA to create InfoPath forms.  Or you might try using the Excel 2003 XML spreadsheet file format with the InfoPath XML data connection.  While both solutions are feasible, they can be a bit clunky to manage multiple files generated from your spreadsheet…
 
Here is your question answered!  Access 2007 provides support for linked tables, virtual tables that pull data from a data source external to an Access database.  Since InfoPath has a built-in database data connection that can query data directly from an Access database, Access 2007 can effectively act as a router for data sources that aren't directly supported by InfoPath.  In this post, we'll step through setting up an InfoPath database data connection that queries data from an Excel spreadsheet.
 
Prepare your Excel spreadsheet
Once you've added all the necessary data to your Excel spreadsheet, save the Excel workbook to a shared network location that will be accessible to all users filling out your InfoPath form.
 
Create the Access database to link the Excel data
Launch Access 2007 and create a new blank database.  When you create a blank database, a default table will be created.  Go ahead and delete the table (just closing the query view should remove the table.)
Switch to the "External Data" tab in the Ribbon

 

Click the "Excel" icon in the "Import" chunk to launch the "Get External Data - Excel Spreadsheet" wizard.
Browse to the Excel workbook that you saved in the "Prepare your Excel spreadsheet" section, above.
Select "Link to the data source by creating a linked table" and then click "OK".

 

Choose the Sheet or Named Range that you want to import, then click "Next >". If the first row of the spreadsheet contains column headers, check the "First Row Contains Column Headings", then click "Next >".

Type a name for the linked table (I'll call it "Spreadsheet" for this post), then click "Finish".
Click "OK" when Access tells you it's done linking the table.  When the dialogs close, you'll see the linked table listed in the "All Tables" task pane

 

Save the Access database to the same directory where the Excel file was saved, then close Access.
 
Design the InfoPath Form Template to Query the Linked Table
Design an InfoPath Form Template based on a "Database" (you could also add the data connection as a secondary database data connection in an existing form template).

 

Once you've clicked "OK", the "Data Connection Wizard" will open.  Click "Select Database…" to open the "Select Data Source" file browser dialog.

Click "New Source…"

NOTE: At this point, it's tempting to just browse to the Access database as you normally would.  However, the default provider used in that case does not support linked tables, so InfoPath will see no tables in the database.  In order to select the appropriate provider, you have to click "New Source…"

 

Select "ODBC DSN", then click "Next >".
Select "MS Access database", then click "Next >".

Browse to the Access database that you created in the "Create the Access database to link the Excel data", above, then click "OK".

NOTE:  This browse dialog can be a bit confusing.  If you get mixed up by the unusual browsing experience, you can just type or paste the full path to the database in the "Database Name" field (boxed in green in the screenshot below).

 

Select the name of the linked table, then click "Next >"
Finish the data connection wizard as you would for any other database data connection.
 
At this point, you're good to go.  The data connection to your Excel data will behave the same as a query-only Access database data connection.


 
- Forrest Dillaway, InfoPath Test