ACC2: No "Can't Add Records" Data Mode Arg. for OpenForm

ID: Q129301


The information in this article applies to:
  • Microsoft Access 2.0


SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

When you set the OpenForm macro action's Data Mode argument, you can select Add, Edit, or Read Only, but the Can't Add Records option that you can select for the form's DefaultEditing property is not available.


RESOLUTION

To work around this behavior, use Access Basic code to pass the specified DefaultEditing property setting in the OpenArgs argument and set the property in the form's Load event. See the "More Information" section for an example of how to use the OpenArgs argument.


STATUS

This behavior is by design.


MORE INFORMATION

The following example demonstrates how you can use the OpenForm macro action's OpenArgs argument to pass the specified data mode for use in a form. By using this argument, you can open a form with the Can't Add Records data mode.

CAUTION: Following the steps in this example will modify the sample database NWIND.MDB. You may want to back up the NWIND.MDB file, or perform these steps on a copy of the NWIND database.

  1. Open the sample database NWIND.MDB.


  2. Open the Employees form in Design view.


  3. Enter the following code for the form's OnLoad event procedure:

    
          Sub Form_Load (Cancel As Integer)
             ' Set the DefaultEditing property to the value passed in the
             ' OpenArgs argument.
             Me.DefaultEditing = Me.OpenArgs
          End Sub 


  4. Save and then close the form.


  5. Open the Utility Functions module in Design view and choose Immediate Window from the View menu.


  6. Type the following statement in the Immediate window and press ENTER:

    DoCmd OpenForm "Employees",,,,,,"4"

    Note that the Employees form opens. You cannot add new records, but all the employee records are available.


You can set the OpenArgs argument to any one of the following values:

   1 = Data Entry
   2 = Allow Edits
   3 = Read Only
   4 = Can't Add Records 

Opening the Form with a Filter

If you set the form's DefaultEditing property to Can't Add Records, you remove any filter that you applied to the form. To open the form so that it retains the filter, use the OpenForm macro action's Filter Name or Where Condition arguments to set the form's DefaultEditing property to Can't Add Records. To pass the filter, use the OpenArgs argument.

For more information about how setting the DefaultEditing property to Can't Add Records removes any filter, please see the following article in the Microsoft Knowledge Base:

Q129302 ACC2: DefaultEditing Set to Can't Add Records Removes Filter

To open the form with a filter, follow these steps:
  1. Change the Employees form's OnLoad event procedure to the following code:
    
          Sub Form_Load ()
             Dim iSemicolon As Integer
             Dim iDefaultEditing As Integer
             Dim sWhereCondition As String
    
             ' Find the semicolon.
             iSemicolon = InStr(Me.OpenArgs, ";")
    
             ' If the semicolon is found...
             If iSemicolon > 0 Then
                '...parse the DefaultEditing and Where Condition arguments...
                iDefaultEditing = Left(Me.OpenArgs, iSemicolon - 1)
                sWhereCondition = Mid(Me.OpenArgs, iSemicolon + 1)
    
                '...and set the arguments.
                Me.DefaultEditing = iDefaultEditing
                If sWhereCondition <> "" Then
                   DoCmd ApplyFilter , sWhereCondition
                End If
             End If
          End Sub 


  2. Type the following statement in the Immediate window and press ENTER:

    DoCmd OpenForm "Employees", ,,,,,"4;[Employee ID]=9"

    Note that the form opens with a filter, and you cannot add new records.



REFERENCES

For more information about the DefaultEditing property, search for "DefaultEditing," and then "AllowEditing, DefaultEditing Properties" using the Microsoft Access Help menu.

Keywords : kbusage FmsProp
Version : 2.0
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: April 9, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.