apress pro access 2010 development phần 5 potx

58 317 0
apress pro access 2010 development phần 5 potx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

CHAPTER 9  ENHANCING PRODUCT ADMINISTRATION 234 2. Select the txtKeywords control and its associated label. From the Arrange tab of the ribbon, click the Stacked button. This will create a layout control with two columns. Click the Insert Right button three times to create a total of five columns. Click the Insert Below button to add a second row. 3. Select the txtKeywords control and the two columns to the right and merge them into one cell. 4. Make sure the control wizards are turned on by clicking the dropdown icon to see all the form controls. The Use Control Wizards icon should be highlighted. 5. Click the Combo Box button and then click the Basic page. In the first Combo Box Wizard dialog box, select the second option as shown in Figure 9-14. Figure 9-14. Selecting the option to specify the combo options 6. In the next dialog box, enter the following values, as shown in Figure 9-15. • <Any field> • Author • Title • Description CHAPTER 9  ENHANCING PRODUCT ADMINISTRATION 235 Figure 9-15. Specifying the allowed values 7. In the final dialog box enter Look In as the label text. Set the Name property of this control to cbField. In the Data tab, set the Default Value property to “<Any field>.” Set the Limit To List property to Yes. Set the Allow Value Lists Edits to No. Drag the control to the second cell of the bottom row. 8. Add another ComboBox control to the Basic page. This time, in the Combo Box Wizard, select the first option, which is to get the values from a table or query. 9. In the second dialog box, select the Media table, as shown in Figure 9-16. Figure 9-16. Selecting the Media table for the combo box source CHAPTER 9  ENHANCING PRODUCT ADMINISTRATION 236 10. In the third dialog box, shown in Figure 9-17, select the MediaID and MediaDescription columns to be included. Figure 9-17. Selecting the columns to be included 11. In the fourth dialog box, shown in Figure 9-18, select the MediaDescription field for the sort option. Figure 9-18. Sorting by the MediaDescription column 12. The fifth dialog box, shown in Figure 9-19, shows a preview of what the Combo Box will look like. Leave all the default settings. CHAPTER 9  ENHANCING PRODUCT ADMINISTRATION 237 Figure 9-19. The Combo Box preview 13. In the final dialog box enter Include as the label text. Set the control’s Name property to cbMedia. In the Data tab, set the Default Value property to 0. Set the Allow Value Lists Edits to No. Drag the control to the fourth cell of the bottom row. This cbMedia Combo Box will allow you user to select one of the media types. You also want to provide an option to include all of the media types in the search, which will require another row in the dropdown list. To do that you’ll modify the query that populates this control. 1. Select the cbMedia control and in the Data tab of the Property Sheet, select the Row Source property. Click the ellipses, which will launch the Query Builder. Select the SQL View. Replace the existing SQL with the following code: SELECT [Media].[MediaID], [Media].[MediaDescription] FROM [Media] UNION SELECT 0, "<All media>" FROM [Media] ORDER BY [MediaDescription];  Tip This SQL uses a UNION clause to add an additional hard-coded value to the values supplied by the Media table. The value 0, with a description of <All media>, will indicate that the search should look in all media types. 2. Close the Query Builder and click the Yes button when prompted to update the property. 3. Select all the labels and set the Text Align property to Right. CHAPTER 9  ENHANCING PRODUCT ADMINISTRATION 238 4. Add a command button to each of the cells in the far-right column. Just cancel the control wizards when they launch. For the top button, enter BasicSearch for the Name property and Search for the Caption. For the lower button, enter the BasicClear for the Name property and Clear for the Caption. Save the form and enter the name ItemSearch when prompted. The layout of the Form Header should look like Figure 9-20. Figure 9-20. The layout of the Form Header  Note To add other search methods, such as the Advanced tab, you would add unbound controls for specifying the search criteria. You then implement a Search button that formats a filter based on those criteria. I will leave the implementation details for you to work out on your own. Designing the Detail Section Now you’ll design the results section of the ItemSearch form. It will use the Continuous Form View, so all of the controls that you place here will be repeated for each record returned by the search. Just like with the CustomerSearch form you created in Chapter 7, the detail section will contain data-bound controls. You will limit the records that are displayed with a filter that is generated based on the specified search criteria. 1. In the Property Sheet, select the Form object and the Data tab. For the Record Source property select the Item table. 2. Set the following form properties: • Filter On Load: Yes • Allow Additions: No • Allow Deletions: No • Allow Filters: No • Allow Edits: Yes (this is needed to be able to enter the search criteria) • Default View: Continuous Forms • Record Selectors: No CHAPTER 9  ENHANCING PRODUCT ADMINISTRATION 239 • Navigation Buttons: Yes • Close Button: No • Filter: [ItemID] = CLng('0') (This will prevent items from displaying until the search criteria is entered.) 3. In the Design tab of the ribbon, click the Add Existing Fields button. Double- click the ItemID and Picture fields to add them to the Detail section. Delete their associated labels. Prefix the Name property of both of these controls with “txt.” For example, the Name property of the Picture control should be txtPicture. Set the Visible property to both of these controls to No. Drag both of these controls to the top-left corner of the Detail section. 4. Click the Add Existing Fields button in the ribbon. Double-click the following fields to add them to the form and then delete the associated labels: • Author • Title • Description 5. In the Other tab of the Property Sheet, change the Name property for all three controls to prefix them with “txt.” For example, txtAuthor. 6. Select all three of these controls and set their Locked property to Yes to prevent the user from modifying these fields. 7. With these controls still selected, from the Arrange tab of the ribbon, click the Stacked button to create a layout control. Click the Insert Left button to add a column to the left of the existing column. Merge all three cells of the left column into one cell. 8. Select the entire layout, click the Control Padding button, and then click the None link. This will remove the spaces between the controls. 9. Drag the layout to the top-left corner of the Detail section. 10. Add an Image control to the left cell of the layout. Set the Name property of this control to imgPicture. In the Data tab, for the Control Source property enter =GetFullImagePath([txtPicture]). This binds the Picture property of the Image control to the txtPicture control that specifies the filename. The layout should look like Figure 9-21. Figure 9-21. The layout of the Detail section CHAPTER 9  ENHANCING PRODUCT ADMINISTRATION 240 11. Right-click the Cancel button and click the Build Event link. This should display the Macro Designer. The existing macro calls the Close Window action. Change the Save parameter from Prompt to No. Save the macro changes and close the Macro Designer. 12. Select the OK button. In the Event tab of the Property Sheet, change the On Click property from Embedded Macro to Event Procedure. Change the Name property to Close. Adding the VBA Code In the Design tab of the ribbon, click the View Code button, which will generate a code file for this form and display the VBA Editor. Enter the code shown in Listing 9-3. Listing 9-3. Initial Implementation of the ItemSearch Form Private Sub Close_Click() If (Me.CurrentRecord = 0) Then MsgBox "Please select an item first", vbExclamation, "No Item Selected" Else Me.Visible = False End If End Sub Private Sub Form_Current() txtSelectedItemID = Me.ItemID End Sub Private Sub BasicSearch_Click() Dim s As String Dim sFilter As String If (IsNull(Me.txtKeywords) Or Len(Me.txtKeywords) <= 1) Then MsgBox "Please enter a keyword", vbExclamation, "No Keyword Specified" Else s = "*" + Me.txtKeywords + "*" sFilter = "(([Author] Like '" + s + "' And ([Forms]![ItemSearch]![cbField] " & _ "= '<Any field>' Or [Forms]![ItemSearch]![cbField] = 'Author'))" & _ "Or ([Title] Like '" + s + "' And ([Forms]![ItemSearch]![cbField] " & _ "= '<Any field>' Or [Forms]![ItemSearch]![cbField] = 'Title'))" & _ "Or ([Description] Like '" + s + "' And ([Forms]![ItemSearch]![cbField] " & _ "= '<Any field>' Or [Forms]![ItemSearch]![cbField] = 'Description')))" & _ "And ([MediaID] = [Forms]![ItemSearch]![cbMedia] Or " & _ "[Forms]![ItemSearch]![cbMedia] = CLng('0'))" DoCmd.ApplyFilter "", sFilter, "" End If End Sub CHAPTER 9  ENHANCING PRODUCT ADMINISTRATION 241 Private Sub BasicClear_Click() txtKeywords.Value = Null cbField = "<Any field>" cbMedia = cbMedia.DefaultValue End Sub The Cancel button simply closes the form. However, the event handler for the OK button (implemented in the Close_Click method) merely hides the form. This allows the calling form to retrieve the selected item. This is the same way that you implemented the CustomerSearch form. In a Continuous Form, each record is displayed as a mini form which is repeated as many times as necessary. When you click on a record, that specific “form” becomes the current one and the OnCurrent event is raised. The Form_Current event handler takes advantage of this and captures the ItemID of the selected record. The BasicSearch_Click method is called when the Search button is clicked. It builds a filter string based on the input criteria and then calls the ApplyFilter method. Unlike the CustomerSearch form, it is assumed here that the only partial values are entered so the keyword is automatically prefixed and suffixed with the “*” wildcard character. The BasicClear_Click method clears the txtKeywords control and restores the default value for the ComboBox controls. Testing the Search Function Now you’re ready to try it out. Save the code file and the form changes, then switch to the Form View. Enter a keyword or phrase and click the Search button. The form should look like Figure 9-22. CHAPTER 9  ENHANCING PRODUCT ADMINISTRATION 242 Figure 9-22. The ItemSearch dialog Using Conditional Formatting You probably noticed that you can’t tell which item is selected. You could turn on the Record Selectors property, which will display a black arrow next to the selected item. However, I’ll show you another way to highlight the selected record, using the Conditional formatting feature. 1. Open the ItemSearch form in the Design View. In the Detail section, right-click the txtAuthor control and click the Conditional Formatting link as shown in Figure 9-23. CHAPTER 9  ENHANCING PRODUCT ADMINISTRATION 243 Figure 9-23. Selecting the Conditional Formatting link 2. This will display the Condition Formatting Rules Manager, shown in Figure 9- 24. The txtAuthor control is already selected, and there are no rules currently applied to this control. Click the New Rule button, which will display the New Formatting Rule dialog box. Figure 9-24. The Conditional Formatting Rules Manager 3. Select the first option since you’ll be using an expression and change the combo box to Expression Is. For the expression enter the following code. The txtSelectedItemID control is in the Form Header and the OnCurrent event handler updates this to store the ID of the item that is currently selected. The expression uses this to return True if the record being displayed has the same ID as the selected record: [txtItemID] = [txtSelectedItemID] 4. Finally, you need to specify in the rule what to do when the expression is true. Click the Background Color dropdown and select a background. This will be used when displaying the selected record. The completed rule should look like Figure 9-25. [...]... OnBeforeNavigate event To do so, in the Property Sheet, select the On Before Navigate property, select Event Procedure and then click the ellipses Add the following code for this event’s implementation If (Left(CStr(URL), 17) "http:/ /apress. com") Then Cancel = True End If This code will prevent navigating to any URL that doesn’t start with apress. com.” 250 CHAPTER 9  ENHANCING PRODUCT ADMINISTRATION  Note... USysRibbons when prompted 4 Open the table in the Datasheet View Enter Demo in the RibbonName field Enter the XML shown in Listing 10-1 in the RibbonXML field and save the record The table should look like Figure 10- 15 Figure 10- 15 The contents of the USysRibbons table Close the Access database and then re-open it Access should have loaded your custom ribbon, but now you need to tell Access to use it 5 Click... 4 Change the Name property of the Picture control to txtPicture Set the Visible property to No 5 In the Design tab of the ribbon, click the Image button and then click in the Detail section Cancel the control wizard Drag this control to the empty cell on the right side of the form Set the Name property to imgPicture 6 In the Data tab of the Property Sheet, set the Control Source property to =GetFullImagePath(txtPicture)... link Select each page and set the Name property of each to Operations, Administration, and Maintenance The form should look like Figure 10-1 Figure 10-1 The initial Menu form layout 3 256 In the Property Sheet, select the Form object and set the Record Selectors and Navigation Buttons properties to No These are not applicable for this form, because it does not access a table CHAPTER 10 ENHANCING THE... OpenForm action 5 In the second dialog box, select the CheckOut form, as shown in Figure 10-4 257 CHAPTER 10 ENHANCING THE USER EXPERIENCE Figure 10-4 Selecting the CheckOut form 6 The third dialog box, shown in Figure 10 -5, provides an option to filter the record when opening the form This doesn’t apply in this scenario, so select the second option, which is to show all records Figure 10 -5 Selecting the... the large empty cell that you just created Cancel the control wizard when it starts In the Property Sheet set the name of this control to webBrowser 5 Now you’ll add a couple of event handlers Select the webBrowser control In the Event tab of the Property Sheet, for the On Navigate Error property, select Event Procedure and click on the ellipses Enter the following code for the implementation This simply... the other Access techniques that you learned include: • Importing tables from another Access database • Using conditional formatting • Calling an action query from a command button • Using page breaks In the next chapter, you will make changes to this application to prepare it for the end users This will include creating a navigation form and locking down the design and development features 254 C H A... “welcome” form that will present to the user their choices of things they can do such as check out a customer, look for an item, and so on Access 2010 provides a really nice facility for creating a navigation form by simply dragging the forms and reports to the appropriate navigation structure However, the complex forms you have developed so far will not work with this technique Essentially, the navigation... button is not enabled, it’s probably because you clicked inside the subform, selecting one of its cells Try clicking on the border of the subform The Property Sheet will indicate if you have selected the InventoryItem subform 249 CHAPTER 9  ENHANCING PRODUCT ADMINISTRATION 2 The bottom row will have two cells, merge these together into one Expand the height of the cell to be about 5 inches 3 In the Design... tab of the ribbon, click on the Page Break button, as shown in Figure 9-34 251 CHAPTER 9  ENHANCING PRODUCT ADMINISTRATION Figure 9-34 Clicking the Page Break button 2 Then click on the Item form, just above the webBrowser control You should see a series of dots, shown in Figure 9- 35, which indicates a page break Figure 9- 35. The page break indicator 3 Now you’ll add buttons to the Form Footer that . following values, as shown in Figure 9- 15. • <Any field> • Author • Title • Description CHAPTER 9  ENHANCING PRODUCT ADMINISTRATION 2 35 Figure 9- 15. Specifying the allowed values 7 Builder and click the Yes button when prompted to update the property. 3. Select all the labels and set the Text Align property to Right. CHAPTER 9  ENHANCING PRODUCT ADMINISTRATION 238 4. Add. completed rule should look like Figure 9- 25. CHAPTER 9  ENHANCING PRODUCT ADMINISTRATION 244 Figure 9- 25. The New Formatting Rule dialog box 5. Click the OK button to close the dialog

Ngày đăng: 12/08/2014, 15:22

Từ khóa liên quan

Mục lục

  • Enhancing Product Administration

    • Implementing Item Search

      • Testing the Search Function

      • Using Conditional Formatting

      • Invoking the ItemSearch Form

      • Enhancing the Item Form

        • Adding an Inventory Item

        • Adding a Web Browser

        • Using Page Breaks

        • Modifying the CustomerLoan Form

        • Summary

        • Enhancing the User Experience

          • Form Navigation

            • Creating the Menu Form

            • Auto-Loading the Menu Form

            • Ribbon Navigation

              • Implementing a Sample Ribbon Tab

              • Displaying the System Objects

              • Building a Custom Ribbon

                • Designing the Tables

                • Creating the Menu Forms

                • Populating the Menu Tables

                • Using MSO Images

                • Implementing the Custom Ribbon

                • Locking Down the Database

                  • Removing Navigation

                  • Compiling the Database

                  • Summary

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan