3 4
Access 2002 gives you several different choices when creating data access pages. After you start the process by choosing Pages in the database window Objects bar and clicking New, you select the style that fits the data you want to publish to the Web. Unlike the other Access components, in which the New Form (or New Report) dialog box offers you all the available layout selections, data access page layout choices are divided between two dialog boxes: the New Data Access Page dialog box and the Layout Wizard dialog box, which appears when you drag fields to a new data access page.
Table 18-1 lists all the available options for creating data access pages.
note
Table 18-1. The Data Access Page Creation Options
Creation Option | Available From |
Columnar | AutoPage: Columnar selection in the New Data Access Page dialog box Columnar selection in the Layout Wizard |
Tabular | Tabular selection in the Layout Wizard |
Banded | Page Wizard selection in the New Data Access Page dialog box |
Free-Form | Design View selection in the New Data Access Page dialog box |
PivotTable | PivotTable selection in the Layout Wizard |
PivotChart | PivotChart selection in the Layout Wizard |
Office Spreadsheet | Office Spreadsheet selection in the Layout Wizard |
From Existing Web Page | Existing Web page selection in the New Data Access Page dialog box |
Saving a Form as a Data Access Page | Choose File, Save As from an open Access form |
To create a new data access page, either click Pages in the database window Objects bar and then click the New button, or click the New Object selector and select Page from the drop-down list, as shown in Figure 18-4.
Figure 18-4. You can create a data access page based on a table using the Page item in the New Object selector drop-down list.
The New Data Access Page dialog box opens, as shown in Figure 18-5.
Figure 18-5. You can use the New Data Access Page dialog box to create a data access page.
The New Data Access Page dialog box offers you the following four choices:
As mentioned earlier, the Layout Wizard offers the other choices for creating data access pages. To use this wizard, start a data access page by using the Design View selection in the New Data Access Page dialog box, and then drag a table or query from the field list to the data access page grid. The Layout Wizard displays, as shown in Figure 18-6.
Figure 18-6. You can also create a data access page using the Layout Wizard.
The Layout Wizard offers you the following five choices:
PivotTables and PivotCharts on Data Access Pages
Although both Access forms and data access pages can host PivotTables and PivotCharts, you create these Office Web controls somewhat differently on forms and data access pages. When you create a new form, the New Form dialog box offersyou (among other choices) a choice of AutoForm: PivotTable, AutoForm: PivotChart, and PivotTable Wizard. These selections provide assistance (more in the case of PivotTables) with setting up a form with a PivotTable or PivotChart, as described in Chapter 12, "Using PivotTables and PivotCharts to Analyze Data." The form itself is bound to data, which can be displayed in either PivotTable or PivotChart view.
With data access pages, on the other hand, the New Data Access Page dialog box offers no choices for PivotTables and PivotCharts. You place PivotTables, PivotCharts, and Office Spreadsheets on a data access page by clicking the corresponding tool in the Toolbox, or by dragging a table or query to the data access page design grid and selecting PivotTable, PivotChart or Office Spreadsheet in the Layout Wizard.
Note that you can't create a PivotTable or PivotChart on an Access form and then copy it to a data access page; you must re-create these components on a data access page.
As mentioned, data access pages combine the features of both forms and reports in one object. However, they are neither a form nor a report. If you want to create a data access page that looks like a form and displays one record of information at a time, you can choose the AutoPage: Columnar option in the New Data Access Page dialog box. This option will help you create a form with fields displayed in a vertical column; the Columnar selection in the Layout Wizard offers you the same choice, but with your choice of fields.
If you want a data access page that looks as much as possible like a regular Access form (perhaps to provide Internet users with a familiar interface), the option to save a form as a data access page is the best way to go. This new option allows you to convert a form into a virtually identical data access page, so users of your applications can review, add, and analyze data in the form over an intranet or the Internet.
To create a columnar data access page, just select the AutoPage: Columnar selection from the New Data Access Page dialog box with a table selected. Figure 18-7 shows a data access page based on tblTasks (see the sidebar "Creating Table Relationships On the Fly in Data Access Pages") created using this selection.
Figure 18-7. This columnar data access page was automatically created from tblTasks.
From Figure 18-7 you can see that the value in the ID field is right-aligned and the field is a little bit too wide. You will probably want to make the TaskID field narrower and left-aligned. To make the text box narrower, switch to Design view, click the TaskID text box so that its sizing handles appear (they are small white squares at the corners and midpoints of the text box), grab the handle on the right side of the text box and drag it inwards until the text box has the right width. To make its text left-aligned, with the text box selected, click the Align Left button on the toolbar. (These properties can also be set in the text box's properties sheet, which can be opened by clicking the Properties button on the toolbar.).
Working with controls on data access pages is now quite similar to working with controls on forms or reports, so you can generally use the techniques described in Chapter 8, "Using Design Tools," when working with controls on data access pages.
To create a columnar data access page using the Layout Wizard, create a new data access page using the Design View selection in the Data Access Page dialog box, drag a table or query from the field listField list to the data access page's design grid, and then select the Columnar selection from the Layout Wizard. The only difference between the two methods is that the Layout Wizard Columnar selection allows you to select a subset of the fields in a data source, while the New Data Access Page AutoPage: Columnar selection automatically places all the fields in the selected table or query on the data access page.
If you want complete control over the placement of fields on a data access page, select the Design View choice in the New Data Access Page dialog box, and drag fields to the design grid from the Field List, placing them as desired on the data access page design grid.
Creating Table Relationships On the Fly in Data Access Pages
If you preselect a table or query before you create a new data access page, the selected table will be expanded in the Field List, ready for you to drag fields from it to the data access page design grid. However, unlike Access forms and reports, data access pages allow you to drag fields from any table in the current database to the data access page, as long as those fields can be related to the original table.
In the Modified Northwind database available on the companion CD, for example, tblTasks has a field (Assigned Person) that can be related to the Person field in tblPersons. After you drag fields from tblTasks to the design grid, dragging a field from tblPersons to a data access page opens the Layout Wizard first. Choosing a type of data access pageand then clicking OK opens the Relationship Wizard (shown in Figure 18-8), which allows you to create a link between the two tables on the fly.
Figure 18-8. You can set up a relationship in the Relationship Wizard after dragging a field from another table to the data access page grid.
Relationships set up in the Relationship Wizard opened from a data access page do not appear in the regular Relationships window or as links when you create queries based on these tables.
In Access 2002, you can create a data access page with a hierarchical structure by grouping records on it into specific categories. Grouping records on a data access page is similar to grouping records on a report. To create a banded (also called grouped) data access page, you can either use the Page Wizard selection in the New Data Access Page dialog box, or select the Create Data Access Page By Using Wizard shortcut in the Pages tab of the database window.
To create a banded data access page by using the Page Wizard, follow these steps:
Figure 18-9 shows a sample query called qryNorthwindAll based on several Northwind tables. This query is located in the Modified Northwind.mdb database.
Figure 18-9. This query is intended for use as a data access page data source.
The New Data Access Page dialog box opens with qryNorthwindAll selected.
Figure 18-10. The first page of the Page Wizard looks like this.
Selecting Salesperson, ProductName, Customer, OrderDate and Price allows you to create a banded page using several categories.
Figure 18-11. Select groups for a banded data access page on the second page of the Page Wizard.
Figure 18-12. The final page of the Page Wizard allows you to specify the page title and other options.
You have several options before finishing the wizard: You can choose to open the page in Page view or Design view, you can select a theme for the page, and you can display Help for working on a data access page. When you've made your selections, click Finish.
note
If you choose to apply a theme, the Theme dialog box will appear when you click Finish. Figure 18-13 shows the Canvas style. If you click Set Default, the Canvas style will remain the default, so that all the data access pages you create in this database will have a consistent appearance.
Figure 18-13. You can choose to apply a theme to your data access page.
Figure 18-14 shows the data access page open in Design view with a placeholder at the top where you can enter a title.
Figure 18-14. The data access page is now banded and includes a field list.
tip
After you type in the title, you can make changes in Design view. For example, you could add space to the labels and change the size of the controls. When you switch to Page view, the data access page appears with the first product name visible, in collapsed mode, as shown in Figure 18-15.
Figure 18-15. The new data access page is collapsed to show the top level only.
If you click the plus sign to the left of the ProductName label, you'll expand the next level, showing the Customer data; clicking the plus sign to the left of the Customer label expands the Detail group, showing the Salesperson, Order Date, and Price data, as shown in Figure 18-16.
Figure 18-16. In Page view, the new data access page looks like this with all bands of data expanded.
The data access page has three navigation bars that correspond to the Product Name group, the Customer group, and the Detail area. These navigation bars also have buttons for filtering and sorting the data in each group. You can see the number of records in each child group in the navigation bars. For example, the Alice Mutton product has 20 customers and the selected customer (Antonio Moreno Taqueria) has one detail record.
If you want to create a table-type data access page, you can also use the tabular layout selection. As the name suggests, a tabular data access page looks like a table, with labels used as column headings. To create a data access page with a table displaying data fromselected fields, select Design View in the New Data Access Page dialog box, and then drag a table or query from the field list to the data access page grid. When Access displays the Layout Wizard, select Tabular. Figure 18-17 shows a tabular data access page created by dragging tblTasks to the data access page design grid.
Figure 18-17. This tabular data access page displays all fields from tblTasks.
Figure 18-18 shows the tabular data access page with a title added, in Page view.
Figure 18-18. The tabular data access page looks like this in Page view.
If you want the viewers of your data access page to be able to dynamically rearrange summarized data on the data access page, use a PivotTable (or a PivotChart if you want to display the data graphically). These selections let users decide for themselves what information they want in rows, and what information in columns, and how they want to analyze or chart it. For example, one user might want to see salespersons' names as rows, and sales by month in columns, while another user might want to see summarized quarterly sales in rows, and salespersons in columns.
With a PivotTable, each user can decide for himself or herself how to arrange the data, without having to switch to Design view and modify the data access page (which in any case might not be possible, if the user only has read-only permissions for working with the data access page). Similarly, with PivotCharts users can select different chart and graph types, and swap the data displayed on the horizontal and vertical axes, without the need to redesign the data access page.
For a familiar worksheet look, you can use the Office Spreadsheet. You can create data access pages with any of these three Office Web Components by creating a new data access page in Design view and then placing a PivotTable, PivotChart, or Office Spreadsheet control on the design grid. However, the process of creating these controls and filling them with data is generally simpler if you choose the appropriate selection from the Layout Wizard, which appears when you drag a table or query from the data access page's field list to the design grid.
InsideOut
You can't copy a PivotTable or PivotChart from an Access form to a data access page, but if you take the time to create a select query that includes only the data you need in the PivotTable, and does some preprocessing of the data using date and string conversion functions, you can use that same query as the data source for a PivotTable on a data access page, thereby saving you a good deal of time when you place a PivotTable control on a data access page. The query qryNorthwindAll, shown in Figure 18-9, is such a query.
A PivotTable is much more flexible in displaying data than a banded data access page. Users can swap the Row and Column fields, add totals, and filter the data on the form to get just the view they want. You can use the same query that you used to create the banded data access page to create a PivotTable data access page.
To do so, follow these steps:
For more details on working with PivotTables, see Chapter 12, "Using PivotTables and PivotCharts to Analyze Data."
Figure 18-19. Insert a PivotTable control on a new data access page in Design view.
Using Date Functions to Process Date Fields in a Query
When creating a query for use in a PivotTable or PivotChart, you can use several date functions to separate out the data in a Date/Time field into the appropriate time periods, using meaningful words rather than numbers. For example, if you anticipate wanting to display data in months, quarters, or years, you could use the Year, Month, MonthName, and DatePart functions to produce properly formatted column headings, using the following query column expressions:
OrderYear: Year([OrderDate]) OrderMonth: MonthName(Month([OrderDate])) OrderQuarter: "Q" & DatePart("q",[OrderDate]) & ", " & Year([OrderDate])
These expressions produce the following values (for a sample row):
Order Year: 1994 Order Month: September Order Quarter: Q3, 1994
These query columns can then be used to create PivotTable columns or rows, or PivotChart series and categories.
Figure 18-20. Select the PivotTable choice when dragging a query to the data access page design grid.
Troubleshooting - I can't see the drop zones in a newly inserted PivotTable.
If the PivotTable's drop zones aren't visible, right-click the PivotTable control, and then choose Commands And Options from the shortcut menu to open the Commands And Options dialog box. Click the Behavior tab and select the Drop Areas check box, as shown in Figure 18-21. You can also turn on the PivotTable's title bar and toolbar on this page.
Figure 18-21. Turn on a PivotTable's drop zones in the Commands And Options dialog box.
note
Figure 18-22. The PivotTable data access page looks like this in Design view.
Figure 18-23 shows the data access page in Page view.
Figure 18-23. The new data access page looks like this in Page view.
Troubleshooting - I can't add a sum to a PivotTable or change the chart type on a PivotChart.
Although they look normal (they don't appear dimmed), the AutoSum button and other buttons on the PivotTable and PivotChart toolbars aren't available unless the PivotTable (or PivotChart) control is activated. In data access page Design view, click the control once, and then again. (Don't double-click the control. If you do, the Object Properties dialog box will open.) When you see the PivotTable (or PivotChart) surrounded by a wide, diagonally hatched border, you can use the tools on its toolbar.
You can also swap the Row and Column fields of the PivotTable and add totals. Figure 18-24 shows the same PivotTable with Salesperson as the Row field and ProductName as the column field.
Figure 18-24. The same PivotTable looks like this after you swap rows and columns and add totals.
tip
The data access page toolbox doesn't have a PivotChart control. Instead, it has an Office Chart control. In Access 2000, this control put a chart similar to a Microsoft Graph on a form or data access page. In Access 2002, this control places a Microsoft Office Web Component placeholder on a data access page, and you need to select a data source to turn it into a PivotChart. Placing a Chart control on a data access page is primarily useful for creating a PivotChart based on external data, as described in the "Creating a PivotChart Based on an External Data Source" section later in this chapter. If you want to create a PivotChart based on a local table or query, a much simpler method is available as described in the following procedure:
Figure 18-25. Select the PivotChart option on the Layout Wizard when dragging a table or query to a data access page to create a PivotChart.
Figure 18-26. This PivotChart in Design view has its Series, Categories, and Filter fields filled.
Now that you have the PivotChart set up with the data you want to display on it, you can modify the chart in various ways:
tip - Turn on PivotChart Features
Figure 18-27. You can choose from several chart types for the PivotChart.
Figure 18-28 shows the completed PivotChart in Page view.
Figure 18-28. The completed PivotChart looks like this in Page view.
You might want to change a few other properties in the PivotChart's properties sheet, although you should leave most of the properties at their default settings. Generally speaking, if the property is familiar from controls on Access forms, or if it starts with "Display," it is safe to change. For example, you can safely change the FontSize and FontStyle properties, but it's best to leave properties such as Behavior and ClassName alone.
Creating a PivotChart Based on an External Data Source In addition to creating a PivotChart based on a query or table in the current database, you can also create a PivotChart based on a query or table in an external data source, by setting up an OLEDB connection. To create a PivotChart on a data access page based on a query in another Access database, follow these steps:
Figure 18-29. You have three choices for selecting a PivotChart's data source.
Data Source Choices for PivotCharts on Data Access Pages
When selecting a data source for a PivotChart control on a data access page, you have three options:
Data Typed Into A Data Sheet This option lets you manually type the data for the PivotChart into a datasheet. When you select this option, the Data Sheetbutton is enabled. When you click this button, a little datasheet opens so you can fill it in with data.
Data From A Database Table Or Query This option lets you select a table or query in another database as the data source. When you select this option, the Connection button appears on the form, which you can click to set up a connection to the database containing the table or query you want to use as the PivotChart's data source.
Data From The Following Web Page Item This option lets you use the same data as a PivotTable control or Data Source control on the same data access page. When you select this option, the DataSource Details button appears on the form, which you use to select the PivotTable or DataSource control to use as the PivotChart's data source. This is handy if you want to have a PivotTable and a PivotChart displaying the same data on a data access page.
Figure 18-30. Set a connection to a database on the Data Source tab of the Commands And Options dialog box.
Figure 18-31. After selecting the database and query, the Data Details tab is filled with the necessary connection data.
From now on the PivotChart control can be modified just as for one based on a local table or query, as described earlier in this chapter.
The Office Spreadsheet control resembles a Microsoft Excel worksheet, and thus should be familiar to anyone who has worked with Excel. To create an Office Spreadsheet control based on an Access table or query, follow these steps:
note
Figure 18-32. You can adjust the column widths of a Spreadsheet control.
tip
To add a sum to an Office Spreadsheet column, follow these steps:
Figure 18-33. You can create a total for a column in an Office Spreadsheet control by clicking the AutoSum button with a blank cell selected.
InsideOut
Because it is more difficult to add a sum to an Office Spreadsheet control than to a PivotTable, and data in an Office Spreadsheet control can't be rearranged dynamically, you will have more flexibility if you use a PivotTable control rather than an Office Spreadsheet control.
Creating an Office Spreadsheet Control Bound to an Excel Worksheet If you need to display data from an Excel worksheet on a data access page, you can bind the Office Spreadsheet control to data in a worksheet by using the Data Source tab of the Commands And Options dialog box.
To create an Office Spreadsheet control bound to data in an Excel worksheet, follow these steps:
Figure 18-34. The Data Source tab of the Commands And Options dialog box lets you select a worksheet as the data source of an Office Spreadsheet control.
The data from the selected worksheet now appears in the control.
In addition to the data access page types discussed in earlier sections, which are created by selections in the New Data Access Page dialog box or the Layout Wizard that appears when you drag a table or query to the data access page design grid, several other ways are available for you to create data access pages.
Access 2002 allows you to create a data access page by saving a form, a report, a query, or a table in an Access database as a data access page. You can also save tables, views, stored procedures, functions, and forms in an Access project as data access pages. To save an Access form as a data access page, open the form in Form or Design view, choose File, Save As, and then select Data Access Page in the As box.
This new feature works well for simple forms. Figure 18-35 shows a form based on the Northwind Order Details table and the data access page created from it. (Refer to Chapter 5, "Creating Forms for Entering, Editing and Viewing Data," for a detailed discussion of creating a form based on a table.)
Figure 18-35. The data access page on the bottom was created from the simple form on top.
However, if you try to save a more complex form, such as one with an embedded subform, or a record selector combo box, you may get an error message "Microsoft Access is unable to create the data access page," because Access is unable to save the form as a data access page. You can have the equivalent of a record selector combo box or a subform on a data access page, but you must create these features by using dataaccess page tools. For example, a data access page with a PivotTable can use the Filter field to select records for a single employee, and a banded report can display linked records, much like a subform.
tip
Troubleshooting - I get the message "The HTML file associated with this link has been moved, renamed or deleted" when trying to open a data access page
If the saved HTM file for the data access page has been moved or renamed, you can click the Update Link button to search for the current location (or name) of the file; if it has been deleted, though, you will have to re-create it.
And finally, you can open a saved HTM file (for example, a file created in Internet Explorer or FrontPage) as an Access data access page by selecting Existing Web Page from the New Data Access Page dialog box, and then selecting the HTM file for the data access page you want to open from the Locate Web Page dialog box, as shown in Figure 18-36.
Figure 18-36. You can open a data access page from its HTM file.