Microsoft KB Archive/96576

{|
 * width="100%"|

ACC1x: Error Messages When Concatenating Variables or Controls

 * }

Q96576

-

The information in this article applies to:


 * Microsoft Access versions 1.0, 1.1

-

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

When you are concatenating variables or controls in a function or CreateDynaset method, you may receive one of the following error messages:

Can't bind name ' '

  -or-

Type Mismatch

  -or-

1 parameter expected only 0 supplied

These error messages can result if one of the following is true:


 * You have incorrectly declared the data type of the argument being passed to the function.
 * You are including a variable or control name in the function syntax and Microsoft Access is unable to recognize the data type.
 * You are using incorrect syntax to concatenate the variables.

This article presents examples in which these errors occur and explains how to correct them.

&quot;Can't bind name ' 'Error message
You receive the &quot;Can't bind name&quot; 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 function produces the &quot;Can't bind name 'Davolio'&quot; error message:

  Call the function as follows: MyFunction (&quot;Davolio&quot;)

Function MyFunction (DataToFind As String) Dim MyDB As Database, myset As Dynaset Set MyDB = CurrentDB Set myset = MyDB.CreateDynaset(&quot;Employees&quot;) Myset.FindFirst &quot;[Last Name]= &quot; & DataToFind End Function

The correct syntax for the last line of code above is as follows:

  MySet.FindFirst &quot;[Last Name] = '&quot; & DataToFind & &quot;'&quot;

&quot;Type Mismatch&quot; Error Message
You receive the &quot;Type Mismatch&quot; 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 the &quot;Type Mismatch&quot; error message:

  Call the function as follows: MyFunction (3).

Function MyFunction (NumberToFind As integer) Dim MyDB As Database, MySet As Dynaset Set MyDB = CurrentDB Set MySet = MyDB.CreateDynaset(&quot;Employees&quot;) MySet.FindFirst &quot;[Employee ID] = '&quot; & NumberToFind & &quot;'&quot;

The correct syntax for the last line of code above is as follows:

  MySet.FindFirst &quot;[Employee ID] = &quot; & NumberToFind

Keep the following requirements in mind:

 When the argument for an Access Basic 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 &quot;[Hire Date] = #&quot; & DateToFind & &quot;#&quot;   Numeric data types do not require delimiters, as in the following example:

     MySet.FindFirst &quot;[Employee ID] = &quot; & NumericDataToFind 

&quot;1 Parameters Were Expected, But Only 0 Were Supplied&quot; Error Message
You may receive this error message when you use the CreateDynaset method in Access Basic 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. The following sample code generates the error message when Query1 has the parameter &quot;[Enter a Name]&quot; in the Criteria for the Last Name field:

<pre class="FIXEDTEXT">  Function TestQP Dim MyDB As Database, MySet As Dynaset Set MyDB = CurrentDB Set MySet = MyDB.CreateDynaset(&quot;Query1&quot;) Debug.Print MySet![First Name]; Tab(10); MySet![Last Name] End Function

When you refer to the parameter query, the correct syntax is as follows:

<pre class="FIXEDTEXT">  Function TestQP Dim MyDB As Database, MySet As QueryDef, MyDyna As Dynaset Set MyDB = CurrentDB Set MySet = MyDB.OpenQueryDef(&quot;Query1&quot;) MySet![Enter a Name] = &quot;Davolio&quot; Set MyDyna = MySet.CreateDynaset Debug.Print MyDyna![First Name]; Tab(10); MyDyna![Last Name] MyDyna.Close MySet.Close End Function

The same error message may appear when you concatenate a variable in the SQL SELECT statement of a CreateDynaset method. A syntactically correct example is as follows.

NOTE: In the following example, an underscore (_) is used as a line- continuation character. Remove the underscore from the end of the line when re-creating this example.

<pre class="FIXEDTEXT">  Set MySet = MyDB.CreateDynaset(&quot;SELECT * FROM Employees WHERE _                    [Employee ID] = &quot; & Forms!Form1!Field0 & &quot;;&quot;)

This SELECT statement points to a control on a form for the WHERE clause. [Employee ID] is a numeric field type and the contents of the control are numeric.

Additional query words: parameters

Keywords : kberrmsg kbprogramming

Issue type : kbinfo

Technology : kbAccessSearch kbAccess110 kbAccess100