midfde
asked on
MS Access: Is it possible to ennoble 3061 error message?
This simple vba code
Actual SQL code is programmatically generated and is about 1,500 characters long:
Sub t()
On Error Resume Next
Debug.Print "1)", CurrentDb.OpenRecordset("select id from table1")(0)
If Err <> 0 Then Debug.Print Err, Err.Description
Debug.Print "2)", CurrentDb.OpenRecordset("select id, x,y from table1")(0)
If Err <> 0 Then Debug.Print Err, Err.Description
End Sub
returns the following in Immediate Window1) 5
3061 Too few parameters. Expected 2.
Q): Is there a way to extend somehow the output to, say, 1) 5
3061 Too few parameters. Expected 2 ([x],[y])
Although it is irrelevant to the question I illustrate it with a "live" example.Actual SQL code is programmatically generated and is about 1,500 characters long:
?len(stAnoQrysql)
1572
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<<"MS Access knows" means that it can display what I want, and it does not want to pass it to my code see the image. >>
Yes it indeed does, but understand that "Access" is really three things; Access (MSACCESS.EXE) and the UI it presents along with the Access objects (like forms and reports), A DB Engine (JET or ACE) and VBA.
The parameter dialog you showed is coming out of MSACCESS.EXE. But when your running code in VBA, that's out of the picture. Only things involved at that point are VBA and the DB Engine.
So when your executing queries in code, everything is up to you and that includes ensuring that the SQL statement is correct and resolving any parameters before hand.
So if you had the the SQL in a querydef, you would open the querydef, loop through the parameters, and try to resolve each. If you could not resolve one, then you would know which one was the problem and at this point, you could produce a dialog like MSACCESS.EXE does.
To put that another way, if Access handed off a SQL statement to the DB engine without prompting you, you would get the same error from it "Too few parameters. Expected 2" because all the DB engine is reporting back is that it can't execute the statement.
Jim.
Yes it indeed does, but understand that "Access" is really three things; Access (MSACCESS.EXE) and the UI it presents along with the Access objects (like forms and reports), A DB Engine (JET or ACE) and VBA.
The parameter dialog you showed is coming out of MSACCESS.EXE. But when your running code in VBA, that's out of the picture. Only things involved at that point are VBA and the DB Engine.
So when your executing queries in code, everything is up to you and that includes ensuring that the SQL statement is correct and resolving any parameters before hand.
So if you had the the SQL in a querydef, you would open the querydef, loop through the parameters, and try to resolve each. If you could not resolve one, then you would know which one was the problem and at this point, you could produce a dialog like MSACCESS.EXE does.
To put that another way, if Access handed off a SQL statement to the DB engine without prompting you, you would get the same error from it "Too few parameters. Expected 2" because all the DB engine is reporting back is that it can't execute the statement.
Jim.
ASKER
I just wanted to inquire if anybody knows how to ask a right guy (of the three aforementioned, I think it's DB Engine) a right question.
From your comment, I'm not sure exactly what your asking for, but your question was:
Q): Is there a way to extend somehow the output to, say,
To which the short answer is no.
Jim.
Q): Is there a way to extend somehow the output to, say,
To which the short answer is no.
Jim.
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for midfde's comment #a40369144
for the following reason:
Thanks for you attention Jim.
Accepted answer: 0 points for midfde's comment #a40369144
for the following reason:
Thanks for you attention Jim.
ASKER
Thanks for your attention Jim.
ASKER
"MS Access knows" means that it can display what I want, and it does not want to pass it to my code see the image.