Too few parameters expected 1

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • goldstar
    New Member
    • Jan 2008
    • 49

    Too few parameters expected 1

    I currently have a listbox in one of my forms, when selected and delete is pressed i wish to delete this item from the list .
    This is what i have been trying
    [CODE=vb] If MsgBox("Would you like to delete?", vbYesNo, "Confirmati on") = vbYes Then
    Set rstDeleteorderl ibe = CurrentDb.OpenR ecordset("SELEC T * FROM tblorderlist WHERE productID = " & 1stlistbox
    rstDelete.Delet e
    rstDelete.Close
    End if
    [/CODE]
    an error message is being displayed suggesting
    too few parameters expected 1.

    Would anyone know what that means.?
    Last edited by missinglinq; Feb 16 '08, 10:51 PM. Reason: Code tags
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    First off, you're missing a closing parenthesis

    Set rstDeleteorderl ibe = CurrentDb.OpenR ecordset("SELEC T * FROM tblorderlist WHERE productID = " & 1stlistbox)

    Try adding that and see what happens.

    Linq ;0)>

    Comment

    • sierra7
      Recognized Expert Contributor
      • Sep 2007
      • 446

      #3
      Hi
      I think it means you have missed a bracket off the end of your OpenRecordset command ! (and Access is at a loss to interprete what you want)

      Incidentally, the rules are that you should use 'tags' around your code. One advantage is that it is clearer to read and your lines will be numbered so it is easier to reference.

      On second reading I am a bit confused because you seem to have two recordsets "rstDeleteorder libe" and "rstDelete" . If you settle on one name then I think your code should run but personally I would not involve recordsets and just use SQL.
      Code:
      DoCmd.RunSQL "DELETE * FROM tblorderlist WHERE productID = " & 1stlistbox
      Normally, Access will warn you how many records are to be deleted and request confirmation. If you don't want this for your users you can toggle warning off then on again.
      [CODE=vb]
      'turn off warnings
      Application.Set Option "Confirm Action Queries", False

      DoCmd.RunSQL "DELETE * FROM tblorderlist WHERE productID = " & 1stlistbox

      'turn on warnings
      Application.Set Option "Confirm Action Queries", True
      [/CODE]

      S7

      Comment

      • goldstar
        New Member
        • Jan 2008
        • 49

        #4
        Hi

        I have placed a bracket and the end of the open recordset but the same error remains


        Originally posted by sierra7
        Hi
        I think it means you have missed a bracket off the end of your OpenRecordset command ! (and Access is at a loss to interprete what you want)

        Incidentally, the rules are that you should use 'tags' around your code. One advantage is that it is clearer to read and your lines will be numbered so it is easier to reference.

        On second reading I am a bit confused because you seem to have two recordsets "rstDeleteorder libe" and "rstDelete" . If you settle on one name then I think your code should run but personally I would not involve recordsets and just use SQL.
        Code:
        DoCmd.RunSQL "DELETE * FROM tblorderlist WHERE productID = " & 1stlistbox
        Normally, Access will warn you how many records are to be deleted and request confirmation. If you don't want this for your users you can toggle warning off then on again.
        [CODE=vb]
        'turn off warnings
        Application.Set Option "Confirm Action Queries", False

        DoCmd.RunSQL "DELETE * FROM tblorderlist WHERE productID = " & 1stlistbox

        'turn on warnings
        Application.Set Option "Confirm Action Queries", True
        [/CODE]

        S7

        Comment

        • Scott Price
          Recognized Expert Top Contributor
          • Jul 2007
          • 1384

          #5
          What line is highlighted when you get this error message?

          The Delete method when used with a Recordset like you are doing deletes the currently selected record in the recordset only.

          I see at least four problems in your code as it stands in the first post.

          1. You are referring to two different recordsets in the same bit of code.

          2. You need to move to a specific record before using the .Delete method

          3. You appear to be trying to use the .Delete method to delete more than one record at the same time, which it will not allow.

          4. Why are you using recordsets, when as Sierra has already said, the DoCmd.RunSQL is much simpler and cleaner?

          Regards,
          Scott

          Comment

          • Scott Price
            Recognized Expert Top Contributor
            • Jul 2007
            • 1384

            #6
            I just checked again in one of my databases where I am using a command button to delete selected items from a multiselect listbox, and I use the DoCmd.RunSQL method there.

            Also, thanks Sierra for the tip about Application.Set Options! I've always used the generic DoCmd.SetWarnin gs False, which has the disadvantage of turning ALL warnings off, where the SetOptions "Confirm Action Queries" is more specific. I like it already :-)

            Regards,
            Scott

            Comment

            • sierra7
              Recognized Expert Contributor
              • Sep 2007
              • 446

              #7
              Originally posted by Scott Price
              2. You need to move to a specific record before using the .Delete method

              3. You appear to be trying to use the .Delete method to delete more than one record at the same time, which it will not allow.

              Scott
              Well spotted Scott !

              Unless Goldstar does a rstDelete.MoveF irst he is unlikely to delete anything because as you say there is unlikely to be a current record.

              Then if there are more than one record it will require code to MoveNext and loop until all are gone. i.e. when rstDelete.BOF = True and rstDelete.EOF = True.

              S7

              Comment

              • Scott Price
                Recognized Expert Top Contributor
                • Jul 2007
                • 1384

                #8
                I strongly suspicion that the error message he's getting is from not setting the current record in the recordset.

                That's why I asked which line was highlighted in the debugger.

                The parameter that it's expecting with the delete command is a currently selected record, which in this instance is null making for a missing parameter with the .Delete method.

                I still think it's easier and cleaner to use the DoCmd.RunSQL approach, but we'll wait to see what the OP decides before going further with anything :-)

                Regards,
                Scott

                Comment

                • goldstar
                  New Member
                  • Jan 2008
                  • 49

                  #9
                  Thanks for all the info it helped me resolve that, a bit late response, too much things going on at once....


                  but im getting another too few parameters expected 1 but this time i have used brackets, i like using this method as i feel comfortable and with not much experience it gets me through. any help would be appreciated

                  dbase.Execute ("UPDATE tblitem SET isselected = False WHERE hireno = '" & lsttransaction & "'")

                  This is updating my table items by setting the selecting item to false when the hireno equals the 1sttransaction.

                  It must be a bug to see the same question reappear, but im new to this game and i really appreciate all the help

                  Comment

                  • sierra7
                    Recognized Expert Contributor
                    • Sep 2007
                    • 446

                    #10
                    Hi

                    I am assuming that you have set-up the 'dbase' object correctly so you are just trying to execute an SQL string.

                    Your SQL looks ok (it's missing a final semicolon but that might be ok), so long as [hireno] is a character field not a number. If it was a number you would not need the quotes around [lsttransaction ] so your code would be;-

                    Code:
                    dbase.Execute ("UPDATE tblitem SET isselected = False WHERE hireno = " & lsttransaction & ";")
                    S7

                    Comment

                    Working...