Visual Basic Concepts

Format Objects

See Also

Format objects allow you to format and unformat data passed between a database and a bound object. You can also use the traditional Format function to format your data, but format objects offer these advantages:

Types of formatting available from format objects include the standard types supported by the Format function (currency, date/time, string) plus the types in the following table.

Formatting option Description
Boolean Specifies values displayed in the bound control when data read from the database is a Boolean true or false. Writes a Boolean true or false to the database when the data matches a specified value.
Binary Allows any binary data to be read from and written to the database.
Object Allows an object to be read from and written to the database.
Picture Allows a picture to be read from and written to the database.
Checkbox Values read from the database will determine the Value property for a checkbox. Checkbox Value property settings will determine true/false values written to the database.

Stepping Through the Process

You can set formatting options in code or using property pages available from the bound control's DataFormat property in the property window. When the bound control fetches a record from the database, formatting is applied according to properties of the StdDataFormat object, then the Format event is fired and data is displayed by the bound control.

When data is written back to the database, the formatting you applied goes with it. In most cases this works fine, but if you use the Format property to apply complex formatting you may create strings your database cannot unformat. In these cases you need to unformat the data in the Unformat event before it is written to the database.

Understanding the Object Hierarchy

Format objects include: