A question about the error message "Run-time error '3061' Too few parameters, Expecte (1 Viewer)

dariyoosh

New member
Local time
Today, 10:50
Joined
Mar 8, 2010
Messages
6
A question about the error message "Run-time error '3061' Too few parameters, Expecte

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:
Code:
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 DAO.Database object. Here is my code:
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
 

DCrake

Remembered
Local time
Today, 09:50
Joined
Jun 8, 2005
Messages
8,632
Re: A question about the error message "Run-time error '3061' Too few parameters, Exp

You need to put [] around your field name [numval] MOD 2

Access thinks that numval MOD 2 is a field name
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 09:50
Joined
Sep 12, 2006
Messages
15,613
Re: A question about the error message "Run-time error '3061' Too few parameters, Exp

but note also that this on its own doesnt do anything (necesseraily)

myDatabase.Execute strSQL, dbFailOnError


you also need to add an onerror trap


...
...
onerrorr goto fail
myDatabase.Execute strSQL, dbFailOnError
...
...
exit sub


fail:
'error handler
'etc


=========
i think that otherwise an error may transfer to the last active error handler - which may not continue as you expect.
 

dariyoosh

New member
Local time
Today, 10:50
Joined
Mar 8, 2010
Messages
6
Re: A question about the error message "Run-time error '3061' Too few parameters, Exp

You need to put [] around your field name [numval] MOD 2

Access thinks that numval MOD 2 is a field name


Hello there,

Thank you for your attention to my problem, I modified the strSQL in the following way

Code:
strSQL = "UPDATE mytesttable SET numval = ([numval] * 2) WHERE (([numval] MOD 2) = 0)"
But again the same error (sorry I'm a beginner in VBA:))


Kind Regards,
Dariyoosh
 

dariyoosh

New member
Local time
Today, 10:50
Joined
Mar 8, 2010
Messages
6
Re: A question about the error message "Run-time error '3061' Too few parameters, Exp

but note also that this on its own doesnt do anything (necesseraily)

myDatabase.Execute strSQL, dbFailOnError


you also need to add an onerror trap


...
...
onerrorr goto fail
myDatabase.Execute strSQL, dbFailOnError
...
...
exit sub


fail:
'error handler
'etc


=========
i think that otherwise an error may transfer to the last active error handler - which may not continue as you expect.


Yes, exactly, thanks a lot for this remark. Actually I was just trying to focus on the error message in this thread that's why I didn't include an appropriate error handler.

Thanks a lot

Kind Regards,
Dariyoosh
 

DCrake

Remembered
Local time
Today, 09:50
Joined
Jun 8, 2005
Messages
8,632
Re: A question about the error message "Run-time error '3061' Too few parameters, Exp

Create a select query and in column 1 insert field numval, in column 2 enter x:[NumVal] MOD 2

Next view iin datasheet mode to see what X equals

Then in the condition row under the second column enter 0

view again, you will see only the even number appear

Now change the query type to Update and change it [Numval]*2
Run it
 

dariyoosh

New member
Local time
Today, 10:50
Joined
Mar 8, 2010
Messages
6
Re: A question about the error message "Run-time error '3061' Too few parameters, Exp

Create a select query and in column 1 insert field numval, in column 2 enter x:[NumVal] MOD 2

Next view iin datasheet mode to see what X equals

Then in the condition row under the second column enter 0

view again, you will see only the even number appear

Now change the query type to Update and change it [Numval]*2
Run it


Many thanks for your help,

It worked!
:D
 

Users who are viewing this thread

Top Bottom