How to Use Access Database Combo Boxes

Combo boxes are a very useful feature of Accessmouse 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 countriesAccess will bring up a combo box Wizard form.
Your form may require name, address and countryAs we are getting the information for our combo box
details. If for example you wanted to record the Unitedfrom a query we created earler you should select the
Kingdom. The United Kingdom can be known by afirst option 'that says 'I want the combo box to look up
few other names. For example UK, England, Greatthe values in a table or query".
Britain and Britain. Now if you entered a differentClick the 'Next' button
country name each time you wanted to use the UnitedNow the Wizard is asking you where your combo box
Kingdom this can be problematic for a number ofinformation 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 youcreated a query earlier I am going to select the
have in the UK you would get a misleading result. YourqryCountries query.
query may bring up all customers in the UK if youAccess will now ask which fields you want to show in
enter this as criteria for searching, but what aboutyour 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 Americaoccasion.
There is also the possibility of spelling a countryClick the 'Next' button to contiunue
incorrectly. If you have one record with Brazil andAccess will now ask if you want to set a sort order
another with Brasil then when you come to searchfor 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 isAccess will now show you how your combo box data
known in Microsoft Access as a combo box. This willis likely to look
also speed up data entry because you will be selectingYou 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 Ithe edge of the column headings until the mouse
prefer to use a query. The reason for this is you canpointer becomes a cross arrow shape. Now drag the
filter out the items you need in a query. Supposing youcolumn 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 toedge of the ID column to the left until it cannot be seen.
the ones you need. Also there will be a performanceNow 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 willClick 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 keyAccess 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 containwe are not dealing with relating tables at this stage I
Field Name: CountryID (with a data type ofwill 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. TheWe 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 justbutton.
created.That's it, we are done
1) Select both fields in the table and add to the queryNow run the form
gridUse the down arrow on the right hand side of the
2) Save the query with a name of qryCountriescombo box to select a record.
Create a new form or open and existing oneAs you can see there is no danger of typing in the
I find it just as easy to create the combo box by usingwrong 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 thefrom so you cannot again type for example 'England,
control wizards button is depressed. You can moveBritain, UK' etc. Just select UK from the combo box or
your mouse over each control in the toolbox to find it'sUS 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