Results 1 to 5 of 5

Thread: SQL Parameter error: Too few parameters. Expected 2

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    I receive the error: Too few parameters. Expected 2. when I run the below code. I have never written a parameter in VB can someone help me out with what is wrong with the below code?

    Data1.RecordSource = "PARAMETERS [FROM DATE] DateTime [TO DATE] DateTime;"
    Data1.RecordSource = "SELECT * from MASTER where DATE_OPENED between [FROM DATE] AND [TO DATE]"

  2. #2
    Addicted Member
    Join Date
    Sep 1999
    Posts
    154
    Data1.RecordSource = "PARAMETERS [FROM DATE] DateTime [TO DATE] DateTime;"
    Data1.RecordSource = "SELECT * from MASTER where DATE_OPENED between [FROM DATE] AND [TO DATE]"

    You will need to do something like this

    "SELECT * FROM MASTER WHERE DATE_OPENED between " & [FROM DATE] & " AND " [TO DATE]"





  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    This syntax does not seem to work in VB so if anyone could help out i would appreciate it; thanks!!!

  4. #4
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308
    Hi, there.

    I didn't figure out how to use Parameter object with Data control. But there is another way:
    Code:
    Dim sql As String
    
    sql = "Select OrderId,CustomerId from orders where orderdate between " & _
        Chr(35) & Text1 & Chr(35) & " and " & Chr(35) & Text2 & Chr(35)     'Chr(35) is #
    Data1.RecordSource = sql
    Data1.Refresh
    Larisa

  5. #5
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308
    OK. I found how to use Parameters. I use NorthWind db

    Code:
    Dim str As String
    Dim qdf As QueryDef
    
    str = "PARAMETERS [Beginning OrderDate] DateTime, " _
        & "[Ending OrderDate] DateTime; SELECT * FROM Orders " & _
        "WHERE (OrderDate Between[Beginning OrderDate] " _
        & "And [Ending OrderDate]);"
    Set qdf = Data1.Database.CreateQueryDef("", str)
    qdf.Parameters![Beginning OrderDate] = CDate(Text1)
    qdf.Parameters![Ending OrderDate] = CDate(Text2)
    Set Data1.Recordset = qdf.OpenRecordset
    Data1.Recordset.MoveLast
    Data1.Recordset.Close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width