FMS Home FMS Software Development Team Blog FMS Facebook Page FMS Twitter
Jump: Search:

Microsoft Access Developer Center

Table Design

Query Design

Form Design

Form Tips and Mistakes

Form Navigation Caption

Using a RecordsetClone

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 Tips

Properties and Validation

Select First Item

Cascading Combo Boxes

Zip, City, State AutoFill

Report Design

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

Add the NoData Event

Annual Monthly Crosstab Columns

Design Environment

Adding Buttons to the Quick Access Toolbar

Collapsing the Office Ribbon for more space

VBA Programming

Using Nz() to Handle Nulls

Avoiding Exits in the Body of a Procedure

Debugging Keys

Setting Module Options

Math Rounding Issues

Rename a File or Folder

Source Code Library

Microsoft Access Module VBA Library

Royalty Free VBA 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 Source Safe

Deployment

Runtime Downloads

Simulating Runtime

Prevent Close Box

Disable Design Changes

Broken References

Missing Package & Deployment Wizard

Terminal Services and RemoteApp Deployment

Avoid Program Files

Microsoft Access Front-End Deployment

System Admin

Disaster Recovery Plan

Compact Database

Compact on Close

Database Corruption

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

Cloud and Azure

Cloud Implications

MS Access and SQL Azure

Deploying MS Access Linked to SQL Azure

Visual Studio LightSwitch

LightSwitch Introduction

Comparison Matrix

Additional Resources

Microsoft Access Help

MS Access Developer Programming

More Microsoft Access Tips

Technical Papers

Microsoft Access Tools

Connect with Us

Email NewsletterEmail Newsletter

FMS Development Team BlogDeveloper Team Blog

Facebook PageFacebook

Twitter with FMSTwitter

FMS Support Site Support Forum

 

 

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.


Setting Combo Box Display Properties

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.


Selecting the First Item with the ItemData Property

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)

Properly Validating Combo Boxes with the ListIndex Property

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

Feedback

Contact Us  l   Web questions: Webmaster   l   Copyright FMS, Inc., Vienna, Virginia
Celebrating our 27th Year of Software Excellence