ACC2000: Run-time error '2448' with BuildCriteria MethodID: Q208970
|
Moderate: Requires basic macro, coding, and interoperability skills.
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.
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.
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)
'******************************************************************
' 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
SetFilter
Note that the Products form is displayed, followed by an Input box requesting the search criteria.
Run-time error '2448':
You can't assign a value to this object.
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.
Additional query words: error searching filtering
Keywords : kberrmsg kbdta
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: May 13, 1999