Error 3061, Too few parameters Expected 1

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hannoudw
    New Member
    • Aug 2010
    • 115

    Error 3061, Too few parameters Expected 1

    I tried to figure out what i did wrong, and i couldn't find the mistake could any one help me ??
    i'm getting this message :Error 3061, Too few parameters Expected 1.
    achat_num and fact_num are both required field.
    Code:
      Dim db As DAO.Database
      Dim dataset1, dataset2 As DAO.Recordset
      Dim sql1, sql2 As String
      Dim maxfactnum, maxachatnum, Article As Long
       
      Set db = CurrentDb
      Set dataset1 = db.OpenRecordset("select nz(max(achat_num),0) as maxAchatNum from achat", dbOpenDynaset)
      Set dataset2 = db.OpenRecordset("select nz(max(fact_num),0) as maxFactNum from Facture", dbOpenDynaset)
      
      maxfactnum = CLng(dataset2![maxfactnum])  'the maximum fact_num in the Facture table
      MsgBox (maxfactnum)
      maxachatnum = CLng(dataset1![maxachatnum]) ' the maximum achat_num in the achat table
      newAchatNum = maxachatnum + 1                ' the new achat_num
      newFactNum = maxfactnum + 1
      MsgBox (newFactNum)
        sql1 = "insert into Facture values(" _
                & CStr(newFactNum) & ",#" & CStr(Forms![testFact]![date_fact]) & "#," _
                & CStr([testFact_Subform].Form![Real]) & "," _
                & CStr([testFact_Subform].Form![After]) & "," _
                & CStr([testFact_Subform].Form![cash]) & "," _
                & CStr([testFact_Subform].Form![diff]) & ");"
        MsgBox sql1
        db.Execute (sql1)
        
        If (Not IsNull([testFact_Subform].Form![achat_num1])) Then
            sql2 = "insert into achat values(" _
                & CStr(newAchatNum) & "," & CStr([testFact_Subform].Form![Article1]) & "," _
                & CStr([testFact_Subform].Form![size1]) & "," _
                & CStr(newFactNum) & "," & CStr([testFact_Subform].Form![quantite_vendu1]) & "," _
                & CStr([testFact_Subform].Form![prix_vente_unitaire1]) & "," _
                & CStr([testFact_Subform].Form![Difference1]) & "," _
                & CStr([testFact_Subform].Form![Type1]) & "); "
            MsgBox sql2
            db.Execute (sql2)  'this line is highlighted with yellow on debug
        End If
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    The usual problem with this error is you have got a field name wrong

    Comment

    • hannoudw
      New Member
      • Aug 2010
      • 115

      #3
      Yes that's what i thought but i checked them zillion time and they are all right field names!!

      Comment

      • hannoudw
        New Member
        • Aug 2010
        • 115

        #4
        The weird thing is that in the prompt message the sql2 seems to be right , cause i got this right value of inserted fields!!
        does any one know the problem ?

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          If you want us to check your SQL I suggest you post your SQL.

          Expecting us to go the extra mile to save you the effort is not likely to win you too much sympathy.

          Comment

          • hannoudw
            New Member
            • Aug 2010
            • 115

            #6
            Code:
            sql1 = "insert into achat values(" _
            newAchatNum,Article1,size1,newFactNum,quantite_vendu1,prix_vente_unitaire1,Difference1,Type1);"

            Comment

            • code green
              Recognized Expert Top Contributor
              • Mar 2007
              • 1726

              #7
              Are you trying to force the value of an auto-number field?

              Comment

              • hannoudw
                New Member
                • Aug 2010
                • 115

                #8
                Yes had an auto number field

                Comment

                • hannoudw
                  New Member
                  • Aug 2010
                  • 115

                  #9
                  the primary key of the ahat table was auto number , i change it to just number but i'm still getting this error :(

                  Comment

                  • hannoudw
                    New Member
                    • Aug 2010
                    • 115

                    #10
                    I solve it
                    And finally ...
                    It seems if we forgot the quot for the string value it gives this error !
                    Thanks a lot guys :)

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32633

                      #11
                      Originally posted by hannoudw
                      hannoudw:
                      Code:
                      sql1 = "insert into achat values(" _
                      newAchatNum,Article1,size1,newFactNum,quantite_vendu1,prix_vente_unitaire1,Difference1,Type1);"
                      I'm glad you managed to solve it, but this is VBA code still. Not SQL.

                      Never mind for now, but it's worth understanding for future questions.

                      Comment

                      • Nur Alina
                        New Member
                        • Jan 2011
                        • 2

                        #12
                        hi, i also faced this problem. what do you mean by the quot for the string value?

                        Comment

                        • NeoPa
                          Recognized Expert Moderator MVP
                          • Oct 2006
                          • 32633

                          #13
                          I won't allow this thread to go off-topic (or deviate from the OP's requirements specifically), but this particular request can be considered relevant so a full answer to your question can be found at Quotes (') and Double-Quotes (") - Where and When to use them.

                          Comment

                          Working...