none
A question about the error message "Run-time error '3061' Too few parameters, Expected 1"

    Question

  • Dear all,


    I would like to ask a question about Execute method in DAO Database object and I would appreciate if you could kindly give me a hand.
    I have an update SQL query operating on a table with a single numerical column. The query multiplies by 2 each even value. I tested on oracle the following SQL query and I observed that it does the job pretty well:

    UPDATE mytesttable SET numval = (numval * 2)
    WHERE (MOD(numval,2) = 0);
    Now I want to run the very same query with VBA  by calling the Execute method of DAP.Database object. Here is my code:

    Public Sub dbExecteCmdExample()
        Dim myDatabase As DAO.Database
        Dim strSQL As String
        
        Set myDatabase = CurrentDb
        strSQL = "UPDATE mytesttable SET numval = (numval * 2) WHERE ((numval MOD 2) = 0)"
        myDatabase.Execute strSQL, dbFailOnError
        
        Set myDatabase = Nothing
    End Sub
    However, when I run the above code, I receive the following error message:

    Runtime Error: 3061: Two few parameters, expected 1.

    I have been googling for a while for this error message on different forums, yet I haven't managed to deal with this problem.

    Any idea?

    Where is the error in my program?


    Thanks in advance,

    Kind Regards,
    Dariyoosh
    Monday, March 08, 2010 4:18 PM

Answers

  • strSQL = "UPDATE mytesttable SET numval = (numval * 2) WHERE = ((numval MOD 2) = 0)"

    you should use parameters ! 

    or  strSQL = "UPDATE mytesttable SET numval = (numval * 2) WHERE = " ' & numval MOD 2) = 0 & "'" )"  '"



    Just Be Humble Malange!
    • Marked as answer by Tim Li Friday, March 12, 2010 9:58 AM
    Monday, March 08, 2010 4:23 PM
  • Ok, my source code was actually good. I had made a mistake in the column tale name!! SO there was no need to use parameters.

    I'm sorry for my lack of attention and once again thank you very much for your help


    Kind Regards,
    Dariyoosh
    • Marked as answer by dariyoosh Friday, March 12, 2010 2:41 PM
    Friday, March 12, 2010 2:39 PM

All replies

  • strSQL = "UPDATE mytesttable SET numval = (numval * 2) WHERE = ((numval MOD 2) = 0)"

    you should use parameters ! 

    or  strSQL = "UPDATE mytesttable SET numval = (numval * 2) WHERE = " ' & numval MOD 2) = 0 & "'" )"  '"



    Just Be Humble Malange!
    • Marked as answer by Tim Li Friday, March 12, 2010 9:58 AM
    Monday, March 08, 2010 4:23 PM


  • strSQL = "UPDATE mytesttable SET numval = (numval * 2) WHERE = ((numval MOD 2) = 0)"
    
    
    you should use parameters ! 
    
    
    
    or  strSQL = "UPDATE mytesttable SET numval = (numval * 2) WHERE = " ' & numval MOD 2) = 0 & "'" )"  '"
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    



    Just Be Humble Malange!

    Hello there,


    Thank you very much for your attention to my problem and sorry for the delay. Actually, I'm a beginner in VBA. According to what I have learnt so far parameters (that is names enclosed within brackets [  ]) allow the user to specify values during RunTime. But here, the value is the column value in the table, so it is already defined and is not a parameter. Anyway, I even to tried to consider the field name as a parameter and I modified the strSQL definition in the following way:

    strSQL = "UPDATE mytesttable SET numval = ([numval] * 2) WHERE (([numval] MOD 2) = 0)"
    But again the same error.

    Also I tried your another solution, that is,
    strSQL = "UPDATE mytesttable SET numval = (numval * 2) WHERE = " ' & numval MOD 2) = 0 & "'" )"  '"
    But I receive syntax error, are you sure about the syntax? I didn't understand what do you mean


    Thanks in advance,


    Kind Regards,
    Dariyoosh

    Friday, March 12, 2010 1:34 PM
  • Ok, my source code was actually good. I had made a mistake in the column tale name!! SO there was no need to use parameters.

    I'm sorry for my lack of attention and once again thank you very much for your help


    Kind Regards,
    Dariyoosh
    • Marked as answer by dariyoosh Friday, March 12, 2010 2:41 PM
    Friday, March 12, 2010 2:39 PM