Listing text options

A combo box or list box can get its values from a simple string called a Value List. The string just contains each item in the list separated by semicolons. If the items in the list are all text, it's best to enclose each item in quotation marks.

For example, Figure 10-4 shows a combo box (named OpsCombo) added to a form. You can see the items in the open combo box: =, Like, <, >, and so forth. You can also see the properties for the control. Notice that the Row Source Type is Value List, and the Row Source is a bunch of little chunks of text enclosed in quotation marks and separated by semicolons. On the form, each little chunk of text is shown as an option on the control's drop-down menu.

Figure 10-4:

Row Source properties for a Value List.

OpsCombo I

OpsCombo I

Figure 10-4:

Row Source properties for a Value List.

Row Source properties

The Row Source for the OpsCombo control is

"=";"Like";"<>";">";"<";">=";"<="

which is why the drop-down menu displays the various comparison operators. You can programmatically change the contents of a Value List combo or list by using the RowSource property. The new Row Source value must follow the rules of syntax, though, with each item separated by a semicolon and each string enclosed in quotation marks.

In code, you can represent a quotation mark as Chr(34) (the 34th ASCII character). That's generally easier that trying to add quotation marks by enclosing them in single quotation marks like ' " ', which doesn't always work and is difficult to read. For example, Listing 10-1 declares a string variable named NewValList and then adds some text, quotation marks, and semicolons to that string.

0 0

Post a comment