Share this Page URL

Chapter 8. Adding Features and Function ... > Running a Visual Basic Procedure by ... - Pg. 299

Adding Features and Function to Forms Me.lstCampaigns.SetFocus Else DoCmd.OpenQuery "qryExpenseReport", acViewNormal, acReadOnly DoCmd.ApplyFilter "CountryFilter" DoCmd.SetWarnings False End If 299 The code we added uses If...Then...Else statements and the IsNull function in each case to check whether the value of the respective list box is Null, meaning that no item is selected in the list. A message box is displayed if no item is selected, and the code then sets the focus on the list box so that a user can select the item he or she wants. Otherwise, the event pro- cedure performs the same actions that we defined in earlier sections. Managing the Data in a Form If you are building a database that will be used by a workgroup or even by several different users in different ways, consider setting properties that affect which views a form can be modified in and whether the data the form displays can be edited. If you want to prevent anyone from making changes to a form's design when it is open in Form view, set the Allow Design Changes property (on the Other tab) for the form to Design View Only. On the Data tab of the Properties dialog box for a form, you can set the Allow Edits, Allow Deletions, and Allow Additions properties. When the Allow Edits property is set to No, saved records can't be edited in the form. The Allow Additions property specifies whether new records can be added to a database by using a form, and the Allow Deletions property controls whether a record can be deleted. You can also set a form's Recordset Type property to Snapshot to make the form's data read-only. Controls such as text boxes, list boxes, and combo boxes have a Validation Rule property that you can set for the control. If you haven't created a validation rule for a field as part of the field's definition in a table, you can create one for a control bound to that field on a form. You can also create an input mask for a control by using the control's Input Mask property. For more information about creating validation rules and input masks, see Chapter 3, "Managing the Consistency, Format, and Integrity of Your Data."