There is also an option to use a Table or Query. You won’t use this feature for this report but I want to show you how it works, because it is a convenient way to add details from another table. If you select the
“Use existing Tables and Queries” option and click the Next button, the dialog box shown in Figure 12-36 will appear.
Figure 12-36. Selecting a table for the subreport
You select the table or query that you want to use as the data source and then select the fields that should be included. The wizard will then create a subreport for you with the specified fields.
2. As you can see, subreports can use either a form or a report. You should keep in mind, however, that when using a form, the subreport will be read-only, even if the form it is based on allows edits. In this case, the CustomerDisplay form is read-only anyway so this is not an issue. The second dialog in the wizard allows you to link the subreport to the master report. Since it found a control named CustomerID in both objects, this field is suggested for linking the subreport, as shown in Figure 12-37. This is the field that you’ll need to link on so leave this selected and click the Next button.
CHAPTER 12 n REPORTS
Figure 12-37. Selecting the link details
3. In the final dialog box, shown in Figure 12-38, enter the name
CustomerDisplay and click the Finish button. The CustomerDisplay form will be added to the Report Header.
Figure 12-38. Specifying the name of the subreport
4. Delete the associated label control and drag the subreport underneath the Checkout Receipt label.
5. With the subreport still selected, go to the Property Sheet and set the Border Style to Transparent.
CHAPTER 12 n REPORTS
6. On the CheckOut report, add another label underneath the subreport and enter the Caption property as The following items were checked out:.
7. Shrink the width of the report by dragging the right edge of the report as far left as it will go.
8. Save the report and entered the name CheckOut when prompted.
The design of the report should look like Figure 12-39.
Figure 12-39. The final design of the CheckOut report
You can test the report by switching to the Report View. Keep in mind that you haven’t setup the correct filter yet so the data will not be correct but you can verify the format looks correct.
Modifying the CheckOut Form
Now you’ll need to modify the CheckOut form to call the CheckOut report when the checkout process is complete. This will be done by adding a few lines of code to the event handler of the Complete button.
1. Close the CheckOut report and open the CheckOut form in the Design view.
2. Right-click the Complete button in the Form Footer and click the Build Event link. This will display the VBA editor and open the Form_CheckOut code file.
3. The complete implementation of the Complete_Click method is shown in Listing 12-1. Add the lines in bold to your code file.
Listing 12-1. The Implementaton of Complete_Click Private Sub Complete_Click()
Dim sSQL As String Dim sFilter As String
CHAPTER 12 n REPORTS
sFilter = "[CustomerID] = CLng(" & txtCustomerID & ") AND [InProgress] = True"
DoCmd.OpenReport "CheckOut", acViewReport, , sFilter, acWindowNormal DoCmd.PrintOut acPrintAll
DoCmd.Close acReport, "CheckOut", acSaveNo If (Len(txtCustomerID) > 0) Then
sSQL = "UPDATE Loan SET Loan.InProgress = False " & _ "WHERE Loan.InProgress=True " & _
"AND Loan.CustomerID=" & txtCustomerID & ";"
Application.CurrentDb.Execute sSQL, dbFailOnError End If
txtCustomerID = ""
txtInventoryItemID = ""
Me.Requery
CustomerDisplay.Visible = False InventoryItemLookup.Visible = False CheckOut.Visible = False
txtCustomerID.SetFocus End Sub
This code builds a filter that returns the items currently being checked out. It then opens the report passing in the appropriate filter. This will override whatever default filter you entered for testing
purposes. The PrintOut command causes the current report to be sent to the printer. Finally the report is closed.
Switch the CheckOut form to the Form View and check out a few items to a customer. You should have a receipt automatically print that looks like Figure 12-40.
Figure 12-40. A Sample Checkout Receipt
CHAPTER 12 n REPORTS
n Tip If you don’t have a printer connected or don’t want to print out the report while testing, just comment out the last two lines. This will open the report in a separate tab but not print it and close it. You can go to that tab to view the report.
Generating InventoryItem Labels
The items that you have available to be checked out will need some sort of inventory identification. This will indicate that the item belongs to your library and include an ID number that uniquely identifies that copy. This is used when checking out an item. You might want to include the title and perhaps a shelf location for re-shelving purposes. You can easily generate these labels in Access using the Label Wizard.
A sample label report is shown in Figure 12-41.
Figure 12-41. A sample label report
Creating an InventoryItemDetail Query
The Label Wizard uses an existing table or query for the data source. The InventoryItem table does not include details such as the Title; these are stored in the Item table. So you must first create a query that contains all the fields you’ll need for the labels.
1. From the Create tab of the ribbon, click the Query Design button.
2. Add the following tables to the query:
• InventoryItem
• Item
• Category
• Media
CHAPTER 12 n REPORTS
n Note The joins between the tables should be set up automatically based on the existing table relationships.
3. Double-click the following fields to add them to the query:
• InventoryItem.InventoryItemID
• Item.ItemID
• Item.Title
• Item.Author
• Category.CategoryCode
• Media.MediaCode
4. Save the query and enter the name InventoryItemDetail when prompted.
The query design should look like Figure 12-42.
Figure 12-42. The InventoryItemDetail query design
CHAPTER 12 n REPORTS
Using the Label Wizard
Now you’ll use the Label Wizard to build a report that will generate the inventory labels. The wizard has to first identify the label stock that you’re using so it can align the data properly. Then you’ll format the label by specifying the text to be printed on each line. To launch the Label Wizard, from the Create tab of the ribbon, click the Label button.
Selecting the Label Stock Template
Access ships with a large selection of pre-formatted templates. Just choose the vendor and then select from the list of product numbers. You can also define your own template, if necessary. Select the Avery 2160 label stock as shown in Figure 12-43.
Figure 12-43. Selecting the label stock