Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
In this course, author Adam Wilbert illustrates how to create and leverage real-world queries and turn raw data into usable information. The course covers setting up queries, performing calculations, using the built-in Access functions to further refine query results, and identifying top performers or areas for improvement based on a range of criteria.
In the last movie we look at how we could take the value from a drop-down menu on a form and use it as a criteria and a query. In this movie, I want to take a quick look at how the combo box was created and how the state names are populated in the drop-down list. I've currently got that form frm_ EmployeeLookup opened. Let's go ahead and switch into Design view. We'll take a look at the Properties for this form by clicking on the object. If it is not open, you can open up the Property Sheet and then we'll switch to the Data tab. We can see that the Row Source for this particular object includes this long code.
Now I can see that the select statement here indicate that this is a query in SQL view. If I click on the Build button we'll open the same query in the Query Design window. Now this query is embedded in the form. You won't find it anywhere in the navigation pane. I can run the query to see the results that are being returned and we notice that we have a column for the abbreviation for the state and the state name. Let's take a look at this in Design view again. So the query that's populating the drop- down menu is using the table States. From that we've got a field for the abbreviation and the field for the state name.
We're also using a second field of the StateName to sort it ascending, but we're not showing it, so this is providing the alphabetical list. Now this brings up an interesting question. In the drop-down menu we only see the full state nam. We're not seeing the abbreviation and now that we're thinking about it, how do the full state name in the form match up to the abbreviated state name that the query returned? Let's run that query again so you can see what I'm saying. We'll close this query, we'll return to the Form view, and we will run our form. I'll go ahead and select Colorado.
We'll run our query and we'll see that Access is matching the full state Colorado to the query with the abbreviated state CO. So what's going on here? Both of these questions can be answered by taking a look at the default way that the Combo Box Wizard creates an embedded query. Let's go to the wizard and create another combo box to see what's going on. We'll go back to the form and switch into Design view. We'll take our combo box object, click on that once, and we'll set a second combo box anywhere in the form.
If you click once, the Combo Box Wizard will open. Now the first step here is to create the combo box and it'll get the values from another table or query. We'll go ahead and say Next. We'll select our States table here and say Next. Access will ask us what fields from the states contain the values you want to include in the box? Let select Abbreviation and StateName. We add that to the Selected Fields and say Next. You can go ahead and sort ascending by StateName to provide the alphabetical list and we'll say Next again.
Finally here's where the answer is. By default Access hides the key column. If you turn that off Access will display the key column. Let's go ahead and leave ours on. We'll go ahead and say Next. Go ahead and select StateName from the Available Fields to show in the combo box. And we'll say Next and we'll just accept the default name. Press Finish. Let's take a look at this combo box and see how it differs from the one we created previously. We will go into Form view, use the new combo box, and because we decided not to show the abbreviated field, we're getting both here in the drop-down menu.
I can select one and Access displays the first column only in the drop-down menu. So with the ID column hidden, which is Access' recommended option in the wizard, the state name is displayed while the value of the combo box remains linked to the hidden abbreviation. When the query runs it grabs the value of the combo box, not necessarily what's being displayed to the user. Now obviously this could be pretty confusing behavior, which is why I recommend building the embedded query manually as we'll see in Chapter 7. But now that we know that the abbreviation field is simply hidden, we can go back to our original dropdown menu and reveal it with a simple tweak to its properties.
We'll go back into Design view, we'll take a look at the properties for the first drop-down menu, and under the Format tab we'll look for this Column Widths section. We'll see that we have two values here. The first one is 0, the second one is 1. Let's change 0 to 0.5. Click off of it to save that value, switch back into Form view, and now we can see that in our dropdown menu we've revealed both the abbreviation and the full name for the state. So we can see that the value of the box, the abbreviated field, was always there.
It just wasn't displayed; it had a zero width. So that's how we managed to link the full name of the state to the abbreviation in the query. All of this is thanks to the default recommended behavior of the Combo Box Wizard.
There are currently no FAQs about Access 2010: Queries in Depth.
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.