This is the sollution for your trouble: indicate the command object that
you are doing what you are doing, looking for a stored procedure
...
' Execute the Command
Set rst = cmd.Execute(,"sp_Surname_Dup",adCmdUnknown)
*or...
Set rst = cmd.Execute(,"sp_Surname_Dup",adCmdStoredProc)
*or.... before executing*
cmd.CommandType = adCmdStoredProc
*or...*
cmd.CommandType = adCmdUnknown
...Hope this resolves your trouble!
Carlos
> Hello Everybody,
I> am getting the following runtime error while retrieving data from SQL
S> erver stored procedure using ADO 2.6.
"> Command text was not set for the command object" Run time error -
2> 147217908(80040e0c).Please let me know how can I resolve the error.
T> hanks.
*> ****************************************
T> he follwing is my code:
> Dim cnn As ADODB.Connection
> Set cnn = New ADODB.Connection
> Dim cmd As ADODB.Command
> Set cmd = New ADODB.Command
> Dim rst As ADODB.Recordset
> Set rst = New ADODB.Recordset
> > ' Open the connection
> > cnn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
S> ecurity Info=False;Initial Catalog=master;Data Source=DC2019WK06960"
> ' Create the command
> Set cmd.ActiveConnection = cnn
> > ' Execute the Command
> Set rst = cmd.Execute("sp_Surname_Dup")
> Do Until rst.EOF
> With Adodc1
> .RecordSource = "sp_Surname_Dup"
> .CursorType = adOpenStatic
> .EOFAction = adDoMoveLast
> .Caption = rst.RecordCount
> '.Refresh
> End With
> rst.MoveNext
> Loop
> ' Close the recordset
> rst.Close
> Set cmd = Nothing
s> et rst = Nothing
*> ******************************************