Microsoft Access FormsTips and Techniques for Setting and Validating Microsoft Access Combo Box Properties

Provided by: Luke Chung, FMS President

Microsoft Access forms and table datasheets support Combo Boxes to let your users easily enter a selection by providing them with a list of valid values. This makes sure your data is correct and avoids typos:

Country List
Sample combo box listing countries from Total Zip Code Database

Most commonly, the list of values is from a table or query, and can be bound to one field (like an ID field) while displaying a field the user sees and understands. Combo boxes in Access also support the display of multiple columns so you can show more data to make it easier to select the right item.


Here are some tips for using Combo Boxes effectively. FYI, Total Access Analyzer flags any combo boxes in your tables and forms that don't have these properties set correctly:

Set LimitToList to Yes

Set the LimitToList property to Yes, otherwise users can enter values that are not in your list.

Set AutoExpand to Yes

Set the AutoExpand property to Yes to automatically select a matching value in the list as you type.

Increase ListRows

It's annoying to see a short list of options and be forced to scroll to see the remaining few items, or to have a long list and be forced to scroll more than necessary because the number of rows displayed is small -- even though there's plenty of room on the screen!

Increase the ListRows property to display more choices and minimize the need to scroll. The default is number of rows is 8 in Access 2003 or earlier. It is increased to 16 in Access 2007, but that's still low. We would recommend 25 or 30+ if space allows. If the list doesn't have that many rows, the higher number has no impact.

With an unbound Combo Box, you may want to display the first item by default rather than showing a blank value. To do this, use the combo box's ItemData object. ItemData is an array of the combo box list.

For instance, a combo box named cboCountry can be set to the first value in the list by adding this code to the form's OnLoad event:

Me.cboCountry = Me.cboCountry.ItemData(0)

In forms, the BeforeUpdate event is used to validate the entries in the current record. For Combo Boxes, people often check if the value exists by looking for Null like this (where cboName is the name of the combo box):

If IsNull(Me.cboName) Then
  MsgBox "A value is required for ..."
  Me.cboName.SetFocus
  Cancel = True
End If

This flags a missing value, prompts the user, and sets focus to the control, works in most cases, but not all.

If the combo box is on a bound field, there may be an existing value which is not valid. With the combo box set to LimitToList, the field has a value, but you can't see it. Maybe the value was in the list when it was originally selected, but the current list of allowed values has changed.

If you simply check for IsNull, Access says it is not null (which is correct) and you don't handle the invalid entry. What you really want to know is if a valid value was selected. A better check is with the ListIndex property:

If Me.cboName.ListIndex = -1 Then
  MsgBox "A value is required for ...."
  Me.cboName.SetFocus
  Cancel = True
End If

There is no need to check for Null. The ListIndex property returns the number of the selected item (ranges from 0 to the number of items in the list minus 1). If no value or an invalid item is selected, it returns -1 and you can trap it.


Resources for Microsoft Access Forms, Combo Boxes and Tabs

Table Design

Query Design

Form Design

Form Tips and Mistakes

Copy Command Button and Keep Picture

Module VBA to Forms and Controls

Form Navigation Caption

Resync Record in a Subform

Synchronize Two Subforms

Multiple OpenArgs Values

Late Bind Tab Subforms

Subform Reference to Control Rather than Field

Tab Page Reference

Shortcut Keys


Combo Box Top 6 Tips

Properties and Validation

Select First Item

Cascading Combo Boxes

Zip, City, State AutoFill

Report Design

Suppress Page Headers and Footers on the First Page of Your Report

Add the NoData Event

Annual Monthly Crosstab Columns

Design Environment

Add Buttons to the Quick Access Toolbar

Collapse the Office Ribbon for more space

VBA Programming

Basics: Forms and Controls

Run VBA Code from a Macro

Use Nz() to Handle Nulls

Avoid Exits in the Body of a Procedure

Shortcut Debugging Keys

Set Module Options

Math Rounding Issues

Rename a File or Folder

Avoid DoEvents in Loops

Age Calculations

Weekday Math

Send Emails with DoCmd.SendObject

Source Code Library

Microsoft Access Modules Library

Microsoft Access Modules

VBA Error Handling

Error Handling and Debugging Techniques

Error Number and Description Reference

Basic Error Handling

Pinpointing the Error Line

Performance Tips

Linked Database

Subdatasheet Name

Visual SourceSafe

Deployment

Runtime Downloads

Simulate Runtime

Prevent Close Box

Disable Design Changes

Broken References

Remote Desktop Connection Setup

Terminal Services and RemoteApp Deployment

Reboot Remote Desktop

Missing Package & Deployment Wizard

Avoid Program Files Folder

Unavailable Mapped Drives

Microsoft Access Front-End Deployment

System Admin

Disaster Recovery Plan

Compact Database

Compact on Close

Database Corruption

Remove 'Save to SharePoint Site' Prompt from an Access Database

Class Not Registered Run-time Error -2147221164

Inconsistent Compile Error

Decompile Database

Bad DLL Calling Convention

Error 3045: Could Not Use

Converting ACCDB to MDB

SQL Server Upsizing

Microsoft Access to SQL Server Upsizing Center

Microsoft Access to SQL Server Upsizing Center

When and How to Upsize Access to SQL Server

SQL Server Express Versions and Downloads

Cloud and Azure

Cloud Implications

MS Access and SQL Azure

Deploying MS Access Linked to SQL Azure

SQL Server Azure Usage and DTU Limits

Visual Studio LightSwitch

LightSwitch Introduction

Comparison Matrix

Additional Resources

Connect with Us

 

Free Product Catalog from FMS