PRB: Error 13 (Type Mismatch) & Error 3061 w/ SQL Queries

Last reviewed: June 21, 1995
Article ID: Q105171
The information in this article applies to:

- Microsoft Visual Basic programming system for Windows, version 3.0

SYMPTOMS

Incorrect SQL syntax can cause either of the following error messages:

  • Type Mismatch (Error 13)
  • 1 parameter expected but only 0 were supplied (Error 3061)

You may receive one of the above errors with a data access object method that contains a SQL statement, or when using the Refresh method on a Data control that has its RecordSource property set to a SQL statement.

CAUSE

The SQL syntax is incorrect.

RESOLUTION

Correct the SQL syntax. See the examples in the Steps to Reproduce Behavior section below.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Add a data control (Data1) and two command buttons (Command1 and Command2) to Form1.

  3. Set the following properties for the Data1 control:

       Control           Property           Value Set
       ------------------------------------------------------
       Data1             DataBaseName       C:\VB\BIBLIO.MDB
       Data1             RecordSource       Authors
    
    

  4. Add the following code to the Command1 Click event procedure:

       Sub Command1_Click ()
          data1.RecordSource = "Select * from authors where author = 4"
          data1.Refresh        ' This gives the type mismatch error
       End Sub
    
       NOTE: If you change the SQL query to the following, you will receive
       the 3061 error (1 parameter expected but only 0 were supplied):
    
          data1.RecordSource = "Select * from authors where author = brown"
    
       The following query corrects the SQL syntax. It should work correctly
       without giving an error:
    
          data1.RecordSource = "Select * from authors where author = 'brown'"
    
    

  5. Add the following code to the Command2 Click event procedure:

       Sub Command2_Click ()
          Dim db As database
          Dim ds As dynaset
          Set db = OpenDatabase("C:\VB\BIBLIO.MDB")
          sqlquery1$ = "Select * from authors where author = 4"
          Set ds = db.CreateDynaset(sqlquery1$) 'Gives type mismatch error
       End Sub
    
       NOTE: If you change the SQL query to the following, you will receive
       the 3061 error (1 parameter expected but only 0 were supplied):
    
          sqlquery1$ = "Select * from authors where author = brown"
    
       The following query corrects the SQL syntax. It should work correctly
       without giving an error:
    
          sqlquery1$ = "Select * from authors where author = 'brown'"
    
    

  6. From the Run menu, choose Start (ALT, R, S) or press the F5 key to run the program. Click the Command1 button to get the error. Then restart the program, and click the Command2 button to get the error.


Additional reference words: 3.00
KBCategory: kbprg kbcode kbprb
KBSubcategory: APrgDataAcc


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.