ACC97: Run-time error '2448' with BuildCriteria Method

Last reviewed: December 17, 1997
Article ID: Q178198
The information in this article applies to:
  • Microsoft Access 97

SYMPTOMS

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

When you use the BuildCriteria method in Microsoft Access 97 to programmatically set the Filter property on a form, and the Field argument of the BuildCriteria method references a field name that contains a space, you may receive the following error message:

   Run-time error '2448':
   You can't assign a value to this object.

CAUSE

The BuildCriteria method is used to generate a parsed criteria string as it would appear in the Query by Example (QBE) grid or in Filter By Form mode. Unlike the QBE grid or Filter By Form, however, the BuildCriteria method does not automatically enclose the field name within brackets.

RESOLUTION

To resolve this behavior, enclose the Field argument of the BuildCriteria method within brackets. For example, using the example from the "More Information Section" below, the following expression

   strFilter = BuildCriteria("Product Name", dbText, strInput)

should be entered as follows:

   strFilter = BuildCriteria("[Product Name]", dbText, strInput)

MORE INFORMATION

Steps to Reproduce Behavior

  1. Open a new blank database.

  2. From the sample database Northwind.mdb, import the Products table.

  3. Open the Products table in Design view and change the field name "ProductName" to "Product Name" (without the quotation marks).

  4. Close the table.

Creating the Form

  1. On the Insert menu, click Form.

  2. In the New Form dialog box, click Form Wizard, and then click OK.

  3. In the Form Wizard, select Products in the Tables/Queries box, and then add all the fields from the Available Fields box to the Selected Fields box.

  4. Click Finish to build the form.

  5. Close the Form.

Creating the Module

  1. On the Insert menu, click Module.

  2. Add the following function to the module:

        NOTE: In the following sample code, an underscore (_) is used as a
        line-continuation character.
    

        '******************************************************************
        ' This procedure opens a form and applies a filter.
        '******************************************************************
    

        Sub SetFilter()
          Dim frm As Form, strMsg As String
          Dim strInput As String, strFilter As String
    

          ' Open Products form in Form view.
          DoCmd.OpenForm "Products"
    

          ' Return Form object variable pointing to Products form.
          Set frm = Forms!Products
          strMsg = "Enter one or more letters of product name " & _
          "followed by an asterisk."
    

          ' Prompt user for input.
          strInput = InputBox(strMsg)
    

          ' Build criteria string.
          strFilter = BuildCriteria("Product Name", dbText, strInput)
    

          ' Set Filter property to apply filter.
          frm.Filter = strFilter
    

          ' Set FilterOn property; form now shows filtered records.
          frm.FilterOn = True
    

        End Sub
    

  3. To test this procedure, type the following line in the Debug window, and then press ENTER:

           SetFilter
    

    Note that the Products form is displayed, followed by an Input box requesting the search criteria.

  4. Enter "A*" (without the quotation marks) and click OK.

    Note that you receive the error message:

          Run-time error '2448':
          You can't assign a value to this object.
    

REFERENCES

For more information about using the BuildCriteria method, search the Help index for "BuildCriteria" or ask the Microsoft Access 97 Office Assistant.


Additional query words: error searching filtering
Keywords : kberrmsg
Version : WINDOWS:97
Platform : WINDOWS
Hardware : x86
Issue type : kbprb
Solution Type : kbworkaround


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.