ACC2000: You Must Refer to Jet Stored Procedures as Tables in ADOID: Q225918
|
Even though you can programmatically create a Microsoft Jet 4.0 QueryDef (stored procedure), you are unable to access it by using the adCmdStoredProc constant with the CommandText property in ActiveX Data Objects ADO.
Instead of the adCmdStoredProc constant, use the adCmdTable constant of the CommandText property.
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.
http://www.microsoft.com/mcsp/For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.aspCAUTION: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.
Option Explicit
Public Function CreateProc()
Dim strProc As String
strProc = "Create Procedure qryCustByCity " & _
"(prmCity varchar) as " & _
"select * from Customers where City = prmCity"
CurrentProject.Connection.Execute strProc
End Function
The above function creates the following query:
PARAMETERS prmCity Text;
SELECT *
FROM Customers
WHERE (((Customers.City)=[prmCity]));
Public Function RSFromParameterQuery(strCity As String)
Dim prm As ADODB.Parameter
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = "qryCustByCity"
cmd.CommandType = adCmdStoredProc
Set prm = cmd.CreateParameter("prmCity", adVarChar, adParamInput, _
Len(strCity))
prm.Value = strCity
cmd.Parameters.Append prm
Set rst = New ADODB.Recordset
rst.Open cmd
Do Until rst.EOF
Debug.Print rst(0), rst(1), rst(2)
rst.MoveNext
Loop
End Function
?RSFromParameterQuery("London")
For the example above to work, make the following change to the RSFromParameterQuery procedure:Invalid SQL Statement; expected 'DELETE', 'INSERT','PROCEDURE', 'SELECT' or 'UPDATE'
Change the line
cmd.CommandType = adCmdStoredProc
to the following:
cmd.CommandType = adCmdTable
Additional query words: pra
Keywords : kbdta
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbbug
Last Reviewed: July 6, 1999