Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

This article was previously published under Q208970
Moderate: Requires basic macro, coding, and interoperability skills.

↑ Back to the top


Symptoms

When you use the BuildCriteria method 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.

↑ Back to the top


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.

↑ Back to the top


Resolution

To resolve this behavior, enclose the Field argument of the BuildCriteria method within brackets. For example, using the example in step 2 of the "Creating the Module" section of the "Steps to Reproduce Behavior" section later in this article, change the following expression from:
strFilter = BuildCriteria("Product Name", adBSTR, strInput)
				
to:
strFilter = BuildCriteria("[Product Name]", adBSTR, strInput)
				

↑ Back to the top


More information

Steps to Reproduce Behavior

  1. Open a new blank database.
  2. Import the Products table from the sample database Northwind.mdb.
  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

NOTE: The sample code in this article uses Microsoft ActiveX Data Objects. For this code to run properly, you must reference the Microsoft ActiveX Data Objects 2.x Library (where 2.x is 2.1 or later.) To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft ActiveX Data Objects 2.x Library check box is selected.

  1. On the Insert menu, click Module.
  2. Add the following function to the module:
    '******************************************************************
    ' 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", adBSTR, 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 Immediate window, and then press ENTER:
    SetFilter
    						
    Note that the Products form is displayed, followed by an Input box requesting the search criteria.
  4. Type A* and click OK. Note that you receive the error message:
    Run-time error '2448':
    You can't assign a value to this object.

↑ Back to the top


References

For more information about using the BuildCriteria method, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type BuildCriteria method in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB208970, kbprb, kberrmsg

↑ Back to the top

Article Info
Article ID : 208970
Revision : 1
Created on : 12/3/2002
Published on : 12/3/2002
Exists online : False
Views : 286