Autocomplete in VFP9

The textbox class in Visual FoxPro 9 has a new Autocomplete property which shows the user the previous values that have been entered in that textbox. Other properties give you more control over the way that the lookup and autocomplete will work, but at its simplest all you have to do is to set the AutoComplete property true to enable the behaviour.

As the user types into the textbox, a list drops down to show previous entries from that textbox which match the characters entered so far:

Setting up AutoComplete

There are three properties which control the behaviour of AutoComplete. All three are on the Data tab of the Properties window:

1. AutoComplete

This can take five values from 0 to 4:

  1. No autocomplete.
  2. An alphabetical list.
  3. With the most frequently-used values first.
  4. With the most recently-used values first.
  5. In a user-defined order.

The AutoComplete property is the only one that you need to alter to enable the basic autocomplete behaviour. A value of 1 is usually the best choice because the alphabetic order seems to be the easiest for the users to grasp.

2. AutoCompTable

As is typical with Microsoft FoxPro, the architecture is open and the past values are stored in a dbf file. The AutoCompTable property holds the name of this table. If the table does not exist then it will be created when the form opens. If you leave the name blank then VFP will use a table named AutoComp.dbf in the home directory.

The table is opened when the form opens and closed again when the form closes but does not appear in the list of work areas. You can modify the contents of the table with the form on screen and change the AutoComplete behaviour in real time.

3. AutoCompSource

This is the identifying name which will be used to look up past values for the textbox. If you give no name then VFP will use the name of the textbox itself. This means that several textboxes on different forms can share the same list provided that they all have the same name. It also means that all textboxes that you've left at the default name of "Text1" will share the same list.

MS Access technical tips

Visual FoxPro technical tips

General Tips

 

More tips from Alvechurch Data

Alvechurch Data - Microsoft FoxPro and Access Database Development and Training

Alvechurch Data are based close to Birmingham and provide Microsoft Access and Visual FoxPro training, development and support.

Read More

FoxPro Functions

FoxPro has always had functions like FREAD and FWRITE to read and write files at a low level. They can handle files which defeat the STRTOFILE and FILETOSTR functions.

Read More

Development Services

Alvechurch Data specialise in Microsoft Access and Visual FoxPro databases and have fifteen years experience developing databases for small business use.

Read More

Access and Visual FoxPro Training

Microsoft Access and Visual FoxPro training courses and workshops offered by Alvechurch Data in Birmingham.

Read More

Support Services

How Alvechurch Data can help you with maintenance and support of your Access and FoxPro databases.

Read More