======================================================================
  Microsoft(R) Product Support Services Application Note (Text File)
                   WX0637: FORMS QUESTIONS & ANSWERS
======================================================================
                                              Revision Date: 5/93
                                                          No Disk

The following information applies to Microsoft Access, version 1.0.

 --------------------------------------------------------------------
| INFORMATION PROVIDED IN THIS DOCUMENT AND ANY SOFTWARE THAT MAY    |
| ACCOMPANY THIS DOCUMENT (collectively referred to as an            |
| Application Note) IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY      |
| KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO    |
| THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A     |
| PARTICULAR PURPOSE. The user assumes the entire risk as to the     |
| accuracy and the use of this Application Note. This Application    |
| Note may be copied and distributed subject to the following        |
| conditions: 1) All text must be copied without modification and    |
| all pages must be included; 2) If software is included, all files  |
| on the disk(s) must be copied without modification [the MS-DOS(R)  |
| utility DISKCOPY is appropriate for this purpose]; 3) All          |
| components of this Application Note must be distributed together;  |
| and 4) This Application Note may not be distributed for profit.    |
|                                                                    |
| Copyright 1992-1993 Microsoft Corporation. All Rights Reserved.    |
| Microsoft and MS-DOS are registered trademarks and Windows         |
| is a trademark of Microsoft Corporation.                           |
 --------------------------------------------------------------------

1.  Q. How do I invoke my Access Basic code from within a form?

    A. To call a function from a property, type the following:

          =<functionname>()

       The equal sign and parentheses are required.  "<functionname>"
       is merely a placeholder for the Access Basic function.  When
       you type in your function name, do not include the angle
       brackets ("<>").  You can call an Access Basic function from
       form or control properties, such as AfterUpdate or
       DefaultValue. Search for the name of a specific property in
       Help for examples. Subroutines cannot be called from
       properties. For more information, please refer to "An
       Introduction to Programming", Chapter 7, page 1.

2.  Q. Do form rules override table rules?

    A. Yes, form rules do override table rules. When you position
       fields on a form by dragging them from the Field list, the
       validation property for the field inherits the validation rule
       that was defined for the field in the table design.

3.  Q. When is it appropriate to use the exclamation point versus the
       period when identifying objects and properties in an
       expression?

    A. A good rule of thumb is to use the exclamation point before
       anything you specifically name (such as the name of your form
       or a control on the form) and to use a period before anything
       Microsoft Access names (such as a property).

4.  Q. Why doesn't the header I created show in Form view?

    A. The header you created was most likely a page header. There are
       two different types of headers available on forms: form headers
       and page headers. A form header is displayed on-screen and when
       printed; a page header is displayed only when printed.

5.  Q. How do I reference a control on a subform?

    A. To reference the subform control itself, you must use the form
       property of the subform control as follows:

          forms!<masterformname>!<subformcontrolname>.form!<controlname>
          
 6. Q. When are validation rules on a form evaluated?

    A. Microsoft Access evaluates a validation rule only when data is
       entered or edited in a field and the cursor is moved to a
       different field or record. If you leave the field unchanged,
       the validation rule is not evaluated. Microsoft Access also
       validates a field on a form when you leave the form, when you
       switch views, or when you close the form. To check for nulls,
       you must use a macro. For more information, please refer to
       Chapter 22 of the" User's Guide."

7.  Q. How do I create my own record-navigation system on a form
       without using the navigation buttons (called "VCR buttons")?

    A. The Customers form in ORDENTRY.MDB, a sample database supplied
       with Microsoft Access, is an excellent example you can follow
       to create your own record-navigation controls. The navigation
       buttons on this form use generic Access Basic code, which you
       can import to your application.

8.  Q. Why do I get the message "#Error" in some controls on my forms
       or reports?

    A. Microsoft Access places an error value in a field or text box
       on a datasheet or form when it can't find information, execute
       an expression, or store a value within the field's prescribed
       limits. The following list describes the possible error values:

       - #ERROR:  Microsoft Access cannot execute the expression. You
         may have supplied either too few or incorrect arguments for
         an aggregate function. This error also occurs in a table or
         form in which the DefaultValue property for a field or
         control is not appropriate for the DataType or FieldSize
         property setting, or in a query in which the value of a
         calculated field is larger than the FieldSize property
         setting allows. For example, this error message appears if
         you add or multiply two integer values and the resulting
         integer is larger than is permitted in an integer field.
       
         This error also occurs when you substitute an expression for
         a text box and then use the text box's control name within
         the expression, as in the following example:
          
             ControlName:      [Test]
             ControlSource:    =[Test]
          
         Since Microsoft Access automatically sets the ControlName
         property to match the field name, this error commonly occurs
         if you create a text box by dragging a field from the Field
         list box to a form or report.
       
       - #NUM!:  The numeric value is too large (either positively or
         negatively) for Microsoft Access to store in the field, based
         on the current DataType or FieldSize property settings.
      
       - #NAME?:  The ControlSource property you entered for the
         field's value is invalid. This error can result from any of
         the following conditions:
       
          - You have misspelled the ControlSource property.
       
          - You have deleted the ControlSource property itself.
       
          - You have omitted the equal sign (=) when you entered an
            expression for the ControlSource property.
       
       - #DIV/0!:  You tried to divide a number by zero. You can
         neither do this directly in an expression (for example, 8/0)
         nor indirectly by using a value from a field whose numeric
         value is zero.
       
       - #DELETED:  The record to which you referred has been deleted.
         For example, if you or another user deletes a record from an
         underlying table's datasheet, this error value may replace a
         record in a form's datasheet.
      
       - #LOCKED:  Another user has locked this record; thus,
         Microsoft Access cannot read the data.

9.  Q. How can I check for duplicate records immediately after I enter
       a value in a primary key field?

    A. Normally, Microsoft Access does not check the values you enter
       in primary key fields for duplicates until you move to the next
       record. Thus, if you enter an invalid or duplicate value in a
       control (text box) and move to the next record, you may
       invalidate all your previous entries. However, there are two
       methods you can use to force an immediate check for duplicate
       values.

       Method 1:  Create and call a macro that executes a DoMenuItem
       action of the Save Record command from the AfterUpdate property
       of your primary key field. If your record is a duplicate, the
       macro immediately causes the following error message to appear:

          Can't have duplicate key; Index changes were unsuccessful.

       Method 2:  Write an Access Basic function that searches for a
       matching value in a form's dynaset and displays an error
       message if one is found. For example, if you have a form called
       "MyForm" containing a text field called "ID", you can create a 
       function called "CheckDup" as follows:
       
           Function CheckDup (CheckThis)
              On Error goto Err1:
              Dim D As Dynaset
              Set D = Forms!MyForm.Dynaset
              D.FindFirst "ID = '" & CheckThis & "'"
              ' NOTE: The symbols after the first "=" character in the
              ' line above are one single quote and one double quote.
              ' After the last "&" character there is one double quote,
              ' one single quote, and one double quote.
              MsgBox "This is a duplicate record"
              Exit Function
          Err1:
              Exit Function
              Resume Next
          End Function
       
       In this example, you then would type =CheckDup([ID]), where
       "ID" represents the value you entered in the text field, as the
       ID field's AfterUpdate property. When you press ENTER or TAB to
       move to a new control, Microsoft Access immediately searches
       the dynaset for duplicates of your ID value that may already
       appear.


