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: BuildCriteria Method Returns Error for Certain Expressions

View products that this article applies to.


When you use the BuildCriteria method, you may receive one of the following errors:
Run-time error '2431': The expression you entered contains invalid syntax. You may have entered a comma without a preceding value or identifier.
Run-time error '2429': The In operator you entered requires parentheses.
Run-time error '7956': The syntax of the subquery in this expression is incorrect. Check the subquery's syntax and enclose the subquery in parentheses.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

↑ Back to the top


You have used an SQL reserved word for the expression argument of the BuildCriteria method. Specifically, you have used either the word "Select" or "In" for your expression, as in the following example:
BuildCriteria("FieldName", dbText, "IN")

↑ Back to the top


When you use the BuildCriteria method, enclose the expression in single quotation marks, as in the following example:
BuildCriteria("FieldName", dbText, "'" & "IN" & "'")

↑ Back to the top

More information

Both "In" and "Select" are SQL Reserved Words that can be used to indicate the presence of a subquery within a standard SQL statement. When these words are supplied as the expression argument for the BuildCriteria method, Microsoft Access expects a subquery to follow.

Enclosing the expression argument of the BuildCriteria method in single quotation marks will not affect the behavior of the method for text type arguments. The following code fragment gives an example of how this could be applied within Visual Basic for Applications code:
Dim strMsg As String
Dim strInput As String
Dim strFilter As String

strMsg = "Please enter your text."
' Prompt user for input.
strInput = InputBox(strMsg)
' Build criteria string and assign it to a filter string.
' Enclose the user input within single quotation marks
strFilter = BuildCriteria("Region", dbText, "'" & strInput & "'")

Steps to Reproduce Behavior

You can easily reproduce the described errors in the Immediate window, as follows:
  1. Press CTRL+G to open the Immediate window.
  2. Type the following in the Immediate window:
    ?BuildCriteria("Region", dbText, "In")
  3. Press ENTER.
Note that you receive one of the error messages mentioned in the "Symptoms" section. To see the correct output, type the following in the Immediate window
?BuildCriteria("Region", dbText, "'" & "In" & "'")
and press ENTER. Note that you receive the following output:
region = 'in'

↑ Back to the top


For more information about 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.

Also, please see the following articles in the Microsoft Knowledge Base:
208970 ACC2000: Run-time error '2448' with BuildCriteria Method
210610 ACC2000: Issues That Arise When Using the BuildCriteria Method

↑ Back to the top

Keywords: KB197586, kbprb, kbdta

↑ Back to the top

Article Info
Article ID : 197586
Revision : 2
Created on : 6/23/2005
Published on : 6/23/2005
Exists online : False
Views : 444