These error messages can occur if one of the following is true:
- You incorrectly declare the data type of the argument being passed to the function.
- You include a variable or control name in the function syntax and Microsoft Access is unable to recognize the data type.
- You use incorrect syntax to concatenate the variables.
This article presents examples of how these errors can occur and explains
how to correct them.
NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click
References on the
Tools menu in the Visual Basic Editor, and make sure that the
Microsoft DAO 3.6 Object Library check box is selected.
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.
Microsoft Jet Engine error (3070) or "Can't bind name '<argument>'" Error
You may receive the Microsoft Jet Engine error message or the "Can't bind
name '<argument>'" error message when you concatenate a variable or control that has a String data type in a method or function as a Numeric data type. For example, the following sample function produces one of these error messages:
Function MyFunction (DataToFind As String)
Dim MyDB As DAO.Database, MySet As DAO.Recordset
Set MyDB = CurrentDB()
Set MySet = MyDB.OpenRecordset("Employees", dbOpenDynaset)
MySet.FindFirst "[City]= " & DataToFind
End Function
To call this function type the following in the Immediate window, and then press ENTER:
The correct syntax for the last line of the code above is as follows:
MySet.FindFirst "[City] = '" & DataToFind & "'"
"Type Mismatch" or "Data Type Mismatch in Criteria Expression" Error
You may receive the "Type Mismatch" or "Data Type Mismatch in Criteria
Expression" error message when you concatenate a variable or control that
has a Numeric data type in a method or function as a String data type. For
example, the following function produces one of these error messages:
Function MyFunction (NumberToFind As Integer)
Dim MyDB As DAO.Database, MySet As DAO.Recordset
Set MyDB = CurrentDB()
Set MySet = MyDB.OpenRecordset("Order Details", dbOpenDynaset)
MySet.FindFirst "[Quantity] = '" & NumberToFind & "'"
End Function
To call this function, type the following in the Immediate window, and then press ENTER:
The correct syntax for the next to the last line of the code above is as
follows:
MySet.FindFirst "[Quantity] = " & NumberToFind
Keep the following requirements in mind:
- When the argument for a user-defined function or method is a String data type, single quotation marks around the string variable are required.
- Dates passed as a string require the number sign (#). For example:
MySet.FindFirst "[HireDate] = #" & DateToFind & "#"
- Numeric data types do not require delimiters. For example:
MySet.FindFirst "[Quantity] = " & NumericDataToFind
"Too few parameters. Expected 1" Error
You may receive this error message when you use the
OpenRecordset method in code on an existing query. If the query is a parameter query, you need to explicitly declare the parameter and its data type, and set the parameter value for that query in the function.
For example in Query1, which includes fields from the Employees table in
the sample database Northwind.mdb, the following sample code generates the error message when Query1 has the parameter "[Enter a City]" in the criteria for the [City] field:
Function TestQP()
Dim MyDB As DAO.Database, MySet As DAO.Recordset
Set MyDB = CurrentDB()
Set MySet = MyDB.OpenRecordset("Query1", dbOpenDynaset)
Debug.Print MySet![City]; Tab(10); MySet![Region]
End Function
When you refer to the parameter query, the correct syntax is as follows:
Function TestQP()
Dim MyDB As DAO.Database, MyDef As DAO.QueryDef, MySet As DAO.Recordset
Set MyDB = CurrentDB()
Set MyDef = MyDB.QueryDefs("Query1")
MyDef![Enter a City] = "Seattle"
Set MySet = MyDef.OpenRecordset(dbOpenDynset)
Debug.Print MySet![City]; Tab(10); MySet![Region]
MySet.Close
MyDef.Close
End Function
The same error message may appear when you concatenate a variable in the
SQL SELECT statement of an
OpenRecordset method. A syntactically correct example is as follows:
Set MySet = MyDB.OpenRecordset("SELECT * FROM Employees WHERE [City]" & _
" = '" & Forms!Form1!Text0 & "';")
This SELECT statement points to a control on a form for the WHERE clause.
[City] is a Text field type and the contents of the control are Text.