Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2010

    Unanswered: Run Time Error 3061 - Two Few Parameters


    I keep getting this run time error when trying to run some code.

    I know that it is to do with my SQL but not sure exactly where I'm going wrong.

    I've two textboxes on my form and the SQL is looking for values within my database in between these two forms.

    Here is my code

    Dim strSQL As String
    Dim dbs As DAO.Database
     Dim rst As DAO.Recordset
    ' comment - Create SQL string
        strSQL = "SELECT * FROM tblVoucher WHERE tblVoucher.VoucherNo >= [frmGenerate2]![txtstart] And tblVoucher.VoucherNo <= [frmGenerate2]![txtend];"
    ' Open pointer to current database
      Set dbs = CurrentDb()
      ' Create recordset based on SQL
      Set rst = dbs.OpenRecordset(strSQL)
    Then to end my code I have an If statement to tell me wether the SQl returns an empty file or not

    I have this code

    If rst.EOF Then
            'comment - Empty file so OK to enter vouchers
     MsgBox "there are no duplicate values"
       MsgBox "you are creating duplicate values"
       End If
    I'm pretty sure the error is coming from my SQL statement but I can't for the life of me work out why.

    Can anyone help?

  2. #2
    Join Date
    Aug 2009
    Up Nort' Wi
    Too few parameters is the error it kicks up when a field is misspelled, or when you are using the wrong data type (typically). I would check your field names for accuracy.

    Also, you need to break your form values out of the string so it looks at the value and not the string.
           strSQL = "SELECT * " _
                &"FROM tblVoucher " _
                &"WHERE tblVoucher.VoucherNo >= '" &[frmGenerate2]![txtstart] _
                &"' AND tblVoucher.VoucherNo <= '" &[frmGenerate2]![txtend] &"';"
    I'm assuming at this point that txtstart and txtend are text values. if they're numeric then drop the single quotes around the field names (I would also wrap the fields in a proper container: CLng, CInt, CSng, etc to explicitly tell Access what format you want that value to be). If they are date fields then replace the single quotes with # and wrap the fields in CDate.

    Sam, hth
    Good, fast, cheap...Pick 2.

  3. #3
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    best thing to do with SQL query problems is to
    1) assign the SQL to a variable (which you have done)
    2) then examine tha variable to make certain it looks to be valid SQL
    you can do that either as a message box or set a watch / debug break point
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Sep 2010
    cheers guys

    got it sorted!

Posting Permissions

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