Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228

    Run-time error '3061'. Too few parameters. Expected 1.

    Im trying to use a query as part of a command button to have some level of data validation. This is for an orders system and if the value entered (Temp_Quantity) exceeds the remaining value (check_quantity) then I want it to stop and tell the user why.



    Code:
    Dim db As dao.Database
    Dim rs As dao.Recordset
    
    
    Set db = CurrentDb
    
    Set rs = db.OpenRecordset("Quantity_Check")
    
    rs.MoveFirst
    
    Do While Not rs.EOF
    
    If rst!check_quantity < rst!Temp_Quantity Then
       MsgBox "Value entered (" & rst!Temp_Quantity & ") exceeds the available order quantity"
       Exit Sub
       Else
     End If
    
    rs.MoveNext
    Loop
    The query itself works fine, its showing the correct numbers when im testing. I have tripple checked the name of the query and the two fields also. Any ideas on why im getting Run-time error '3061'. Too few parameters. Expected 1.?

    Thank you.

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Try:
    Code:
    Dim db As dao.Database
    Dim rs As dao.Recordset
    Dim qdf as Dao.QueryDef, prm as parameter
    
    
    
    
    Set db = CurrentDb
    
    
    Set qdf =db.QueryDefs("Quantity_Check")
    
    For each prm in qdf.parameters
         prm.value=Eval(prm.name)
    Next prm
    
    
    Set rs = qdf.OpenRecordset
    
    
    rs.MoveFirst
    
    
    Do While Not rs.EOF
    
    
    If rst!check_quantity < rst!Temp_Quantity Then
       MsgBox "Value entered (" & rst!Temp_Quantity & ") exceeds the available order quantity"
       Exit Sub
       Else
     End If
    
    
    rs.MoveNext
    Loop
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Thanks for the reply. I get "object required" using this code here. I'll do some digging.

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    On which line you get that?
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    I also see you have two different recorsets, rs and rst, and you don't set rst anywhere in the code you posted.
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Good spot. Apologies. Same error though.

    on the code you provided it's this line:

    Code:
    If rst!check_quantity < rst!Temp_Quantity Then
    Screenshot here showing query/results.

    Click image for larger version. 

Name:	Screenshot_2.png 
Views:	15 
Size:	6.2 KB 
ID:	41251

    Thank you/

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Can you try
    Code:
    If rs("check_quantity") < rs("Temp_Quantity") Then
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    PMFJI,

    I created a table and a form and added this (modified) code...... I didn't get any execution errors....
    Code:
    Private Sub Command9_Click()    '<<-- my button name
        Dim db As dao.Database
        Dim rs As dao.Recordset
    
        Set db = CurrentDb
    
        Set rs = db.OpenRecordset("Quantity_Check")
        If Not rs.BOF And Not rs.EOF Then               '<<-- Always check to see if records are in the recordset
            rs.MoveLast
            rs.MoveFirst
    
            Do While Not rs.EOF
                If rs!check_quantity < rs!Temp_Quantity Then
                    MsgBox "Value entered (" & rs!Temp_Quantity & ") exceeds the available order quantity"
                    Exit Do   '<<-- changed to "Do" instead of "Sub"
                End If
    
                rs.MoveNext
            Loop
        End If
    
        'clean up
        rs.Close
        Set rs = Nothing
        Set db = Nothing
    End Sub

  9. #9
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Using parts of both sugegstions I now have something working. Thanks a lot both of you.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 12
    Last Post: 10-20-2019, 08:03 PM
  2. Run-Time Error '3061: Too few parameters. Expected 2.
    By Rickochezz in forum Import/Export Data
    Replies: 1
    Last Post: 11-01-2016, 07:29 AM
  3. Replies: 4
    Last Post: 09-28-2016, 07:13 AM
  4. Replies: 5
    Last Post: 03-27-2015, 03:42 PM
  5. Replies: 1
    Last Post: 05-21-2011, 01:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums