Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 58 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
58
Dung lượng
1,37 MB
Nội dung
CHAPTER 5 CREATING PIVOTTABLES 116 Figure 5-23. Collapsing each of the categories This hierarchy of attributes functions much like the CheckedOut By Month field that you added to the Row area. You can collapse or expand specific values to drill down into the data. Using this approach, you can add any number of fields to the Column or Row areas Tip You added the MediaDescription field to the right of the CategoryDescription field. This caused the media type to be a secondary level under category. If you had dragged it to the left the CategoryDescription, then the media type would be the top-level in the hierarchy. Creating a Field Hierarchy When planning these multi-level groupings, you should try to use attributes that are logically related. The date field is the perfect example. Months and weeks are logical subdivisions of a year as are days, hours and minutes. So it is logical to drill down from year to month to day. However, categories and media types are orthogonal attributes. When using multiple fields in a Column or Row area you have to specify the order in which the fields are used in the hierarchy. In this case the category was first so you can see how a summary for each category and then drill down to see what media type were loaned from each category. By placing media type as a sub-group under category, you cannot view a media type across all categories. Someone may prefer to see how a specific media type was represented in each category. You cannot accomplish both at the same time. When you have a situation like this where you need to summarize in both directions, then you should put one attribute in the Row area and the other in the Column area. A better design would be to move the CheckedOut By Month field to the Filter area and move the MediaDescription field to the Row area. Make those adjustments in your PivotTable View and it should look like Figure 5-24. CHAPTER 5 CREATING PIVOTTABLES 117 Figure 5-24. Rearranging the fields in the PivotTable View Notice that you can simultaneously see both category and media type summaries, as well as how the other attribute was represented in the total. Click the dropdown button next to the CheckedOut By Month field in the Filter area. The dialog box shown in Figure 5-25 will appear which you can use to filter the view to include only specific months or days, for example. Figure 5-25. Selecting the dates to include Remember, the Filter field(s) define the set of records that are included in the PivotTable View. By placing the CheckedOut By Month field here, you can control the time period that you want to analyze. Date fields are often a good candidate for a Filter field. However, if you want to see an attribute tracked over time, you will generally use the appropriate date field in Row area. In the current database schema, there is a single-level categorization of items. For a large library you would probably want multiple levels, such as the Dewey Decimal system. The Dewey Decimal system defines three main levels of organization, which are referred to as classes, divisions, and sections. It is called a decimal system because there are 10 classes that each has 10 divisions, which, in turn, has 10 sections each. Thus there are 100 divisions and 1000 sections. If you were to implement a structure such as this, then this would be an excellent candidate for using a multi-level field hierarchy in your PivotTable View. Look for other fields that logically fit into a hierarchy. The Author and Title fields are another good example. CHAPTER 5 CREATING PIVOTTABLES 118 Using the PivotChart View Once you have defined a PivotTable View, you can easily turn this into a graphical presentation. Select the PivotChart View button from the lower right corner or select the PivotChart View link from the View button in the ribbon. The default settings will probably look something like Figure 5-26. Figure 5-26. The initial PivotChart View Configuring a PivotChart View This is a fairly complex PivotTable with several values to chart. Each value is displayed as a bar in this bar graph. To see what each bar represents, you’ll need to display the legend. Click the Legend button in the Design tab of the ribbon. The legend will look similar to Figure 5-27. CHAPTER 5 CREATING PIVOTTABLES 119 Figure 5-27. The PivotChart legend The problem with this chart is that it is trying to display too many values. In a bar chart, the Column field(s) are used to define the bar legend (a color for each column) and the Row field(s) are used for the X axis. Click the “Switch Row/Column” button, which will transpose the Row and Column fields. The resulting chart should now look like Figure 5-28. Figure 5-28. Switching the Row and Column fields This is a little bit easier to follow. For the Classics category, for example, you can now see how each media type contributes to the summary totals Loans, Fees, and Overdue. Notice the dropdown button next to the CategoryDescription and MediaDescription fields. You can use these to filter the records that CHAPTER 5 CREATING PIVOTTABLES 120 are included in the chart. Click the CategoryDescription dropdown and unselect all of the categories except Classics, as shown in Figure 5-29. Figure 5-29. Selecting only the Classics category Changing the Chart Type With the data limited to a single category, you may want to use a different type of chart. Click the “Change Chart Type” button in the ribbon. Select the Line type shown in Figure 5-30. Figure 5-30. Selecting a Line chart The resulting chart is shown in Figure 5-31. CHAPTER 5 CREATING PIVOTTABLES 121 Figure 5-31. The PivotChart View using a line chart You can see from this chart that overdue fees have been charged for Hardback books, but no fees have been charged for DVD videos or paperback books even though there have been overdue items of these media types. Note You will likely have different values in your database. My purpose here is to give you an example of how to read the chart. Now display the PivotTable View by selecting the PivotTable link from the View button. Notice that this view now looks very different from where you left it. This illustrates a very important point: The PivotTable View and the PivotChart View use the same Row, Column, and Filter area definitions. If you change this configuration, it is automatically changed in the other, as well. More subtle and perhaps more significant, you can only have one PivotTable/PivotChart View for each table or query. Caution You can define only one PivotTable/PivotChart View for each table or query. The PivotTable and PivotChart views share the same configuration; when you change one, the other is also updated. CHAPTER 5 CREATING PIVOTTABLES 122 Exporting a PivotTable View to Excel Access 2010 allows you to export a PivotTable or PivotChart view to Excel. This will allow you to manipulate the data and view using the Excel application. As I mentioned earlier, the concepts are similar but the implementation is different. From the PivotTable View, click the CategoryDescription dropdown and select all categories. Save the database and then click the “Export to Excel” button in the Design tab of the ribbon. You will see a pop-up window warning you about possible compatibility issues, shown in Figure 5-32. Click the OK button. Figure 5-32. Compatibility warning Access will then open the Excel application and create a PivotTable worksheet, as shown in Figure 5-33. Notice the similarities to Access 2010 and the differences. Figure 5-33. The PivotTable View in Excel The most obvious difference is that the multi-field hierarchy is not as evident. Notice that the CheckedOut By Month field is replaced by a set of fields, one for each of the data components such as Year, Quarter and Month. The raw data is also imported in the second worksheet, as shown in Figure 5-34. CHAPTER 5 CREATING PIVOTTABLES 123 Figure 5-34. The underlying Excel data Excel uses the raw data that the PivotTable is based on. In order for the PivotTable to work, all of the raw data must be imported, as well. You can use this approach create a new PivotTable and/or chart in Excel using the data from Access and the PivotTable features from Excel. Caution When you export data to Excel, this is a one-time operation. Subsequent changes to the data in Access are not pushed to Excel using manual or automatic means. The only way to update Excel is to re-import the data from Access. Summary PivotTables and charts are an excellent way to present and analyze data from your Access database. You configure a PivotTable or chart by adding one or more fields from the underlying table to each of the following areas: • Data area: This contains the values that ate presented and normally use an aggregate function to summarize the data. • Row and Column: Fields in these areas define the attributes that are used for slicing and dicing the data. • Filter: (Optional) Fields in the Filter are used to limit the data that is being presented. If you specify multiple Row or Column fields, they are added in hierarchical fashion allowing you to drill down from one attribute to the next. The built-in By Month and By Week date fields are an excellent example of this. The most significant limitation to keep in mind is that you can only have one PivotTable/PivotChart View for each table or query. The PivotTable and PivotChart views share the same configuration values; when you change one, both are updated. If you want to create additional PivotTables, refer to Chapter 4 for instructions on how to create a query that joins several tables. You can also export the data and PivotTable to Excel and manipulate the presentation using the Excel tools. 125 P A R T 3 Creating Forms and Reports In Part 2, you created your database, designed the tables, and wrote data macros to implement many of the business rules. You created queries to provide de-normalized views into your data, and even designed a pivot table to analyze the data that is being collected. Although still a bare-bones solution, your database fulfils all the basics requirements. In Part 3, however, you’ll put flesh on those bones and create a rich user experience. Chapter 6 will show you how to use the built-in form templates to easily generate many of the simpler forms. Chapters 7, 8, and 9 demonstrate how to build more complex forms from scratch. This will demonstrate a lot of handy tricks for creating useful forms. Chapter 10 will show you how to create menus and navigation pages that will guide the user to the provided features. In Chapter 11, you’ll focus on the visual, branding aspects of your application, including themes, graphics, and background images. Finally, in Chapter 12, I’ll show how to create reports, which are essentially forms that are designed for print output. C H A P T E R 6 127 Standard Forms One of the really great features of Access is that it can generate forms for you based on your table design. This is another good reason for starting with a well thought out data schema. In this chapter, I’ll demonstrate several common form patterns that will satisfy many of your UI requirements. These are created using standard form templates or the Form Wizard, and do not require writing any code. This chapter will also provide a foundation that applies to both these simple forms as well as advanced custom forms. In subsequent chapters, I’ll show you how to design forms yourself and use macros and VBA code to implement more complex solutions. These custom forms are based on the same general principles that I will explain in this chapter. Creating a Single Form We’ll start by creating a simple form to display records in the Category table. Using the Form Wizard From the Create tab of the ribbon, click the Form Wizard button. In the first dialog box of the Form Wizard, select the Category table, and then move the CategoryCode and CategoryDescription fields to the Selected Fields list, as shown in Figure 6-1. [...]... headings are defined by the Datasheet Caption property Let's change them now, with the following steps: 1 Select the CategoryCode column and then, in the Property Sheet, select the Other tab 131 CHAPTER 6 ■ STANDARD FORMS 2 The default value of the Datasheet Caption property is blank When this is the case, the heading text is defined by the Control Source property, which is the associated column of the... Status from the Control Source property 4 The new Textbox control will have added an associated Label control Delete this, as it is not needed 5 On both the InventoryItemID and Status controls, set the Locked property to Yes You can find this in the Data tab of the Property Sheet 6 Change the Caption property of the InventoryItemID label to ID and set the Text Align property to Left 7 Remove the CurrentLoanID... the Form Wizard with the graphic shown in Figure 6 -22 143 CHAPTER 6 ■ STANDARD FORMS Figure 6 -22 The Tabular layout As I mentioned earlier, Continuous Forms don’t have to follow this pattern You can include labels in the Detail section and arrange the data bound controls in any manner you wish Also, when you chose the Tabular layout, the Default View property of the form is set to Continuous Form Using... situations 1 52 CHAPTER 7 Creating a CheckOut Form In the previous chapter, you created several forms using the design tools provided by Access This is what Access does really well, and this is why it is such a popular platform for creating database solutions It is really easy to create forms for your existing tables The primary constraint, however, is that the standard forms can only access a single... Detail and Form Header section to remove the empty spaces The form in Design View should look similar to Figure 6 -20 141 CHAPTER 6 ■ STANDARD FORMS Figure 6 -20 The completed Design View Select the Form object in the Property Sheet and then select the Format tab Notice that the Default View property is already set to Continuous Form This is set by the Form Wizard whenever you use the Tabular layout ■... changes and select the Form View from the ribbon The final form should look like Figure 6 -21 1 42 CHAPTER 6 ■ STANDARD FORMS Figure 6 -21 The final InventoryItem form Understanding the Layout Options Before I explain the final form that you’ll create in this chapter, I want to review the layout options that are provided by the Form Wizard You use the first dialog box to define the data source for the... ribbon, click the Layout View button 2 Select the label control for the RenewalsAllowed field, which will highlight the control with an orange border 3 Resize this control so it is about half as wide and twice as high The form should look like Figure 6- 12 Figure 6- 12 Resizing the label control 4 Now adjust the column heading in the Datasheet To do that, use the Property Sheet and select the RenewalsAllowed... In the Property Sheet, find the Text Align property in the Format tab and change its value to Right Also select the MediaID and LostFee Label controls and change their Text Align property to Right The form should now look like Figure 6-31 Figure 6-31 The re-arranged Item form Adding a Subform Now you’ll add a subform to show the InventoryItem records for the selected Item You will first need to provide... control wizard in a later chapter 4 In the Data tab of the Property Sheet, select Form.InventoryItem for the Source Object property 5 In the Other tab, change the Name property to InventoryItem You’ll need to enlarge this row so the entire subform can be seen You may also need to make this cell wider Also select the Label control and change its Caption property to Inventory ■ Note The subform only shows a... button in the ribbon If the Property Sheet is not currently visible, click the Property Sheet in the Design tab of the ribbon There is a dropdown list at the top of the Property Sheet that you can use to select the object that you want to view You can select the Form, any of the sections such as Form Header or Detail, or one of the individual controls Because there are a lot of properties, these are grouped . change one, the other is also updated. CHAPTER 5 CREATING PIVOTTABLES 122 Exporting a PivotTable View to Excel Access 20 10 allows you to export a PivotTable or PivotChart view to Excel. This. property. Let's change them now, with the following steps: 1. Select the CategoryCode column and then, in the Property Sheet, select the Other tab. CHAPTER 6 ■ STANDARD FORMS 1 32 2. . CREATING PIVOTTABLES 120 are included in the chart. Click the CategoryDescription dropdown and unselect all of the categories except Classics, as shown in Figure 5 -29 . Figure 5 -29 . Selecting only