Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
At the end of Chapter 03, we took a look at connecting a user input form to a query which then passed data onto a Chart Object. We can do the same thing with a Report. I've got a workflow setup here called SalesByDivision; I am going to start with a SalesByDivision form here. I'll double-click on it to open it and I'll see that this form is asking me for a Geographical Division and a Year and I want to compare it to another Geographical Division and Year. Let's go ahead and fill in some boxes. I'll use the drop-down menus and choose I am interested in the New England Division for 2009 and now I want to compare that data to the Pacific Region for 2009 as well.
Now I've got two buttons here as well. I can either Run the Query or I can Preview a Report. Let's go ahead and press the Preview Report button. I'll press Preview Report and the report generates, showing me New England for 2009 and here is the states and data and then if I scroll down, at the Pacific States 2009 with their states and data. I also have some calculated fields to the very bottom. Both this form and the report have had their designs refined quite a bit. So in this I want to dissect these elements to see how they were designed and some of the decisions that were made to get them to this point.
We'll start where the user starts with the form. I'll go ahead and close the report here and we'll take a look at this form in Design View. I'll switch to Design View here and we can see a couple of things on this form. First, there really aren't all that many elements. In the top left corner I have this logo and the bottom of the logo is a kind of a brown color and the top of this logo has this green color. I've put it in the top left corner of my form and in the top of the form I've put a rectangle. The rectangle is all of this area here in the orange. The rectangle color is set to the same green as my logo. The background of the details section of my report is set to the same color as this light brown.
Down in the bottom right corner I have a tree image. Again we're using the same light brown color for the background of that tree picture. Let's also take a look at this tree, if I click on it and go to the Arrange tab and take a look at it's anchoring here, we'll see that it's set to anchor to the bottom right corner. That means that no matter what size of screen the end-user is looking at, that tree image will always appear in the bottom right corner of their screen. At the top, I have a label. It's just been bolded text and set to white. And then I have my elements down here. I've got a couple of command buttons and I have some combo boxes.
Let's take a look at these combo boxes and I am going to go to the Design tab and turn on my Property Sheet. Let's click on the first combo box here. On the All tab, I'll see that this combo box has a name cbo_division. The box below it has a name as well, cbo_CompDivision. My Year boxes, they have names as well, cbo_Year and cbo_CompYear, so we can make reference to whatever the user selects here in our query later. So let's see where the data is coming from for these drop-down menus. I'll click on the first one again and go to the Data tab.
The Row Source is this SELECT query right here. Let's take a look at the query behind it. I'll press the Build button and we see that there is a pretty simple query, it's pulling in information from my States table and I've got my DivisionName and the DivisionID. I can also see that I am sorting on the DivisionID ascending, but I am not showing it in the list, so why do I have this part here? Well let me run the query and you could see. So when I run the query, I'll notice that my DivisionNames are listed in geographical order, not alphabetical order. And this is important for my end-users. This might be the order that they're more comfortable seeing this data presented in.
Let's go ahead and go back to Design View. And I'll close the query here, we'll take a look at the Year box, it has a Row Source as well, it's also a query, these are embedded queries. I can click the Build button to see its details and this is simply pulling out the Order Date from the Orders table and applying the Year function to it. So when I run it, it's just getting a list of Years that are available within my database. I'll close this out and take a look at the query now. So I've got the names of these boxes that the end-user selects.
Close out the form, and I am not going to save any changes. When I click on those buttons, the query runs. The query that runs is this one right here, the qry_SalesByDivision, I'll right-click on that and take a look in Design View. I'll close the Property Sheet here so I could see the whole thing. And this query is made up of four different tables; Products, Orders, Direct Customers, and States. And then down here in the Criteria, I right-click on this and say Zoom, we'll see the text of that Criteria. The Criteria for the Year field for instance is reading to pull the year from the combo box year on the SalesByDivision form or the CompYear from the combo box on the form.
Go ahead and say OK to that, we'll take a look at the other one; I'll click here, right-click and say Zoom. The Criteria for the DivisionName is also coming from the combo boxes on my form, the cbo_division or the cbo_CompDivision. So if it matches either of the selections from the form, it will show up in the query. Go ahead and say OK and I'll close the query, without saving any changes. The next thing that happens is that the report opens. This is the report down here, rpt_SalesByDivision-complete.
I'll right-click on it and switch to Design View. First we'll go to the Property Sheet and take a look at the Record Source for this report. I can see that it's a linked query, it's linked to that query we're just looking at, the qry_SalesByDivision-complete this is where the data is coming from. It's split into a couple of sections; I've got the Report Header here with the title. The Division Header Name that will show the division every time, the Year Header below that, a Detail section, the DivisionName Footer and scrolling down I've got a Page Footer and a Report Footer. Now each of these boxes have some interesting properties, for instance this SumOfPrice right here is the data that's coming from the query.
Down below that in the DivisionName Footer, I've got another box here that says Division Sales; this is calculating the total sales. And it says equals Sum of SumOfPrice (=Sum([SumOfPrice])). So it's adding up all of the fields here in the SumOfPrice column. But down below that in the Report Footer here, I've got another box and when I click on that I see that it has the exact same formula =Sum([SumOfPrice]), this one is getting the total value of the entire report. Because it's in the Report Footer section, it's aggregating over the entire report. Because this one is in the DivisionName Footer section, it's aggregating over the division name section.
So let's go ahead and close this report and we'll run through that workflow one more time. I'll double-click on the form to open it; I'll choose an area of interest. How about this time East South Central for the year 2009 and we want to compare it to the same section for 2008? We'll Preview the Report and that will open up in Print Preview mode with the data that I'm interested in. So the only thing different is between this and some of the forms and reports that we've created in this course is the amount of time spent fine-tuning the position of the elements, adjusting the colors and fonts and I'm going to admit it, sometimes obsessing over every single pixel.
Step one in creating your forms and reports should always be to get the functionality in place. If the form or report is exceptionally ugly, once it's functioning properly, all the rest is just moving the pieces around. And that part can take a while as you change your View Mode back and forth between Design View, Layout View and Form or Report View, sometimes moving elements one step at a time. It can be tedious sometimes, but the end result will look great and function great.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 70056 Viewers
80 Video lessons · 127442 Viewers
52 Video lessons · 62374 Viewers
59 Video lessons · 48085 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.