| Combo boxes are a very useful feature of Access | | | | mouse button depressed, drag it onto the form. Click |
| and will enhance the look and feel of your forms. | | | | on the form at the position you wish to place it. |
| Let's take an example of countries | | | | Access will bring up a combo box Wizard form. |
| Your form may require name, address and country | | | | As we are getting the information for our combo box |
| details. If for example you wanted to record the United | | | | from a query we created earler you should select the |
| Kingdom. The United Kingdom can be known by a | | | | first option 'that says 'I want the combo box to look up |
| few other names. For example UK, England, Great | | | | the values in a table or query". |
| Britain and Britain. Now if you entered a different | | | | Click the 'Next' button |
| country name each time you wanted to use the United | | | | Now the Wizard is asking you where your combo box |
| Kingdom this can be problematic for a number of | | | | information is coming from. For instance is it coming |
| reasons. | | | | from a table or a query and if so which one? As we |
| If you wanted to search on how many customers you | | | | created a query earlier I am going to select the |
| have in the UK you would get a misleading result. Your | | | | qryCountries query. |
| query may bring up all customers in the UK if you | | | | Access will now ask which fields you want to show in |
| enter this as criteria for searching, but what about | | | | your combo box. It is always a good idea to show the |
| records that have been entered as 'England'? | | | | ID field so I am going to select that as well as the |
| The same problem would occur with the USA, US, | | | | country field. I essentially select both fields on this |
| America, United States of America | | | | occasion. |
| There is also the possibility of spelling a country | | | | Click the 'Next' button to contiunue |
| incorrectly. If you have one record with Brazil and | | | | Access will now ask if you want to set a sort order |
| another with Brasil then when you come to search | | | | for the data in your combo box. You could set this |
| you will get the wrong results. | | | | when creating your query. |
| So how can we get around this problem? | | | | Click the 'Next' button to contiunue |
| The answer is to use a dropdown box or what is | | | | Access will now show you how your combo box data |
| known in Microsoft Access as a combo box. This will | | | | is likely to look |
| also speed up data entry because you will be selecting | | | | You can now adjust the width of the columns in your |
| an item from a list and not typing it in. | | | | combo box. To do this move your mouse pointer over |
| A combo box can use a table as it's data source, but I | | | | the edge of the column headings until the mouse |
| prefer to use a query. The reason for this is you can | | | | pointer becomes a cross arrow shape. Now drag the |
| filter out the items you need in a query. Supposing you | | | | column to suit your preferance. |
| just want a list of European countries on your form. | | | | Also it is good practice to hide the ID field so drag the |
| With a query you could set criteria for this and limit to | | | | edge of the ID column to the left until it cannot be seen. |
| the ones you need. Also there will be a performance | | | | Now you will be left with a single column of data for |
| improvement as queries are faster than tables. | | | | your combo box. |
| You can use any type of data for this lesson, but I will | | | | Click the 'Next' button to contiunue |
| work on using a table of country names. | | | | This next part is rather tricky. |
| 1) Set up a table of countries and have a primary key | | | | Access is asking if you want to store the value you |
| ID field. | | | | select from your combo box or use the value later. As |
| Your table should contain | | | | we are not dealing with relating tables at this stage I |
| Field Name: CountryID (with a data type of | | | | will just leave this step and click the 'Next' button to |
| Autonumber. Make this field a primary key field). | | | | contiunue. |
| Field Name: Country (with a data type of text. The | | | | We are at the final step and Access now asks what |
| length can be around 50). | | | | label name we want to give to our combo box. Type |
| 2) Save the table with a name of 'Countries' | | | | something descriptive in here and then click the 'Finish' |
| Now create a query based on the the table you just | | | | button. |
| created. | | | | That's it, we are done |
| 1) Select both fields in the table and add to the query | | | | Now run the form |
| grid | | | | Use the down arrow on the right hand side of the |
| 2) Save the query with a name of qryCountries | | | | combo box to select a record. |
| Create a new form or open and existing one | | | | As you can see there is no danger of typing in the |
| I find it just as easy to create the combo box by using | | | | wrong information when you have a combo box. Ever |
| the Access Wizard. | | | | record will always have the same values to select |
| Click on the controls tool box and make sure the | | | | from so you cannot again type for example 'England, |
| control wizards button is depressed. You can move | | | | Britain, UK' etc. Just select UK from the combo box or |
| your mouse over each control in the toolbox to find it's | | | | US and your form and data will now become more |
| name shown in a small yellow box. | | | | consistent. |
| Click the control called 'Combo box' and keeping your | | | | |