[RESOLVED] run time error '3061'
I Create an access 97 db with a table named students and connect it with a vb6 form using data control
when i search for the recored between two numbers( the caqlculation of 3 subjects exam) i get a run time error '3061' when execute the code below
can any one you help me in this case
Private Sub Command1_Click()
Dim x As Double
Dim y As Double
x = InputBox(" Enter First Number")
y = InputBox(" Enter SecondNumber")
Data1.RecordSource = "SELECT * From students WHERE sub1+sub2+sub3 > x And sub1 + sub2 + sub3 < y "
Data1.Refresh
End Sub
Re: run time error '3061'
Re: run time error '3061'
I can only guess as to what message is given for error 3061, but I assume it is complaining about x and y (as they only exist in your VB code, not in the database where the SQL statement is running).
This can be solved by putting the values of x and y into the SQL statement instead, as shown in the article How can I put the value of a variable/control into my SQL statement? from the "SQL" section of our Database Development FAQs/Tutorials (at the top of the Database Development forum)
Re: run time error '3061'
3061 = "Application-defined or object-defined error"
Re: run time error '3061'
This needs to be addressed. I'm not precisely sure what you are trying to do here so I going to proceed under the assumption that the "subs" are fields in your database and that each need to contain a value greater than x and less then y to meet your criteria. If this is true then
Code:
'you would need to change this
WHERE sub1+sub2+sub3 > x And sub1 + sub2 + sub3 < y
'to this
WHERE sub1 > x
AND sub2 > x
AND sub3 > x
AND sub1 < y
And sub1 < y
AND sub3 < y
Re: run time error '3061'
Quote:
Originally Posted by MartinLiss
3061 = "Application-defined or object-defined error"
Unfortunately that message is just VB's way of saying "I don't know".
Adding the relevant references/components may well be enough to make it show the proper message, but in some cases (particularly when databases are involved) the error message is actually generated at runtime.
A quick web search on "error 3061" shows many cases of the message being "Too few parameters. Expected n", which is usually caused by the issue I explained - so the link I provided will hopefully solve the error.
Re: run time error '3061'
Same as others, I am not sure what you want to do, perhaps it should be like this:
Data1.RecordSource = "SELECT * From students WHERE (sub1+sub2+sub3) > " & x & " And (sub1 + sub2 + sub3) < " & y
Re: run time error '3061'
Also if you are going to be adding fields then they should be of the proper data types.
sub1+sub2+sub3
Should all be numeric data types.
Re: run time error '3061'
Quote:
Originally Posted by anhn
Same as others, I am not sure what you want to do, perhaps it should be like this:
Data1.RecordSource = "SELECT * From students WHERE (sub1+sub2+sub3) > " & x & " And (sub1 + sub2 + sub3) < " & y
thanks to all
the code above fix the error, and when i type it as show the error '3061' disappeared.
thanks again
Re: run time error '3061'
Now that we've helped you, you can help us by pulling down the Thread Tools menu and selecting the Mark Thread Resolved item which will let everyone know that you have your answer. Also if someone has been particularly helpful you have the ability to affect a their forum "reputation" by rating their post. Only those ratings that you give after you have 20 posts will actually count, but in all cases the person you rate will see it and know that you appreciate their help.
Re: run time error '3061'
Si the Greek, Martin Liss , Hack , Anhn and Robdog888
thank you for your help
i do appreciate that