Condividi tramite


Creating Default Values for View Fields

Like default values for table fields, view field default values are stored in the database and are available each time you use the view. Visual FoxPro doesn't compare the default values you create locally with any default values established on the remote data source. You must create default values that are acceptable for the data source.

To assign a default value to a view field

  • In the Fields tab in the View Designer, select a field, and then choose Properties and enter the default value for the field.

    -or-

  • Use the DefaultValue property of the 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

Updating Multiple Tables in a View | Creating Rules on View Fields and Rows | Creating Queries | Combining Views | Updating Data in a View