Visit our new web pages

We have launched a new extended set of web pages at www.alvechurchdata.co.uk. These old pages will stay on the server because people still have links to them but they will not be updated.

The new version of this page is at www.alvechurchdata.co.uk/hints-and-tips/foxautocomplete.html.

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 it's 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:

[Autocomplete in action]

Setting up AutoComplete

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

[Autocomplete properties]

1. AutoComplete

This can take five values:

  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.

This is the only property 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 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. The structure of the table is described here .

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.


Hints & tips

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.
Autocomplete in VFP 9

Your Access database will look more impressive if you add custom toolbars...
Custom toolbars

FoxPro has always had functions to read and write files at a low level...
Foxpro low level file functions

More...
More pages of hints and tips for users of Microsoft FoxPro and Access databases.

Site Map