Populate a Control from a Data Source
The previous section shows you how to use a database as the primary data source for a form, but you had to know customer or employee codes for the query to work. It would be better if those codes were listed in drop-down list boxes so you could just choose the right criteria (Figure 7-23).
Figure 7-23. Modify the previous sample to populate listboxes from the database
How to do it
In order to populate a listbox from a database, you need to establish a secondary data source. To add a secondary data source to the sample form:
In Design mode, right-click the Customer ID text box and choose Change to → Drop-Down List Box from the pop-up menu. InfoPath converts the control to the new type.
Display the control’s properties (Format → Properties or Alt+Enter) and select Look up in a data connection (Figure 7-24).
Figure 7-24. Select Look up in a data connection to populate a list from a secondary data source
Click Add to select a data source as described in the previous section. In this case, you want to retrieve the Customers table from the Northwind database, as shown in Figure 7-25.
Figure 7-25. Select the fields to retrieve from the Customers table ...
Get Excel 2003 Programming: A Developer's Notebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.