How to: Create Default Values for View Fields

As with table fields, you can specify default values for view fields. These default values are stored in the database and are available when you use the view.

Note

Visual FoxPro does not compare the default values you create locally with any default values stored in the remote data source. You must create default values that are acceptable for the data source.

To specify a default value for a view field

  1. Open the view in the View Designer, and click the Fields tab.

  2. On the Fields tab, select a field, and click Properties.

  3. The View Field Properties dialog box opens.

  4. In the Default value box in the Field Validation area, type the default value for the field.

  5. When you are finished, click OK.

For more information, see Fields Tab, Query and View Designers and View Field Properties Dialog Box.

To specify a default value for a view field programmatically

  • Use the DBSETPROP( ) function with the DefaultValue field property for views.

For more information, see DBSETPROP( ) Function.

For example, you may want your application to limit the amount of merchandise a new customer can order until you've had time to complete a credit check and determine the amount of credit you're willing to extend to that customer. The following example creates a maxordamt field with a default value of 1000:

OPEN DATABASE testdata
USE VIEW customer_view
?DBSETPROP ('Customer_view.maxordamt', 'Field', 'DefaultValue', 1000)

You might also use default values to populate some rows automatically for the user. For example, you might add a Grid Control to an order entry form that is based on a remote view of an order line items table. The order_id field is the key field that maps each row of the Grid to its counterpart in the remote order line items table. Because the order ID for each row in the grid will be the same for one order, you can use a default value to save keystrokes by populating the order_id field automatically.

Tip

If one of your application's business rules requires that a field contain an entry, providing a default value helps to ensure that a particular field-level or record-level rule will not be violated.

See Also

Tasks

How to: Edit Views

Other Resources

Managing Views
Working with Views (Visual FoxPro)