I have created a pass through query and trying to call a stored procedure from it.
I am able to execute the queries on sql server database sucessfully but when it comes to stored procedures, i am getting an error as :
"ODBC call Failed"
The problem is with stored procedures only. The queries are executing fine .
Here , is my code :
Dim qdf As DAO.QueryDef, rst As ADODB.Recordset
Dim DatabaseName As String
Dim Server As String
ServerName = "XXXX"
DatabaseName = "XXX"
Set qdf = CurrentDb.CreateQueryDef("")
strConnectionString = "ODBC;DRIVER={sql server};" & _
"DATABASE=" & DatabaseName & ";" & _
"SERVER=" & ServerName & ";" & _
"Trusted_Connection=YES;"
qdf.Connect = strConnectionString
qdf.SQL = " EXEC [dbo].[SAMPLE_TEST]"
qdf.ReturnsRecords = True
Set rst = qdf.OpenRecordset
Debug.Print rst!RecordCount
rst.Close
Set rst = Nothing
Please let me know if i am missing any thing ?
To get more information about the cause of an "ODBC--call failed." error we can loop through the
DBEngine.Errors
collection and see if there are other messages that might be a bit more descriptive. For example, with the codewe might see the following in the VBA Immediate window:
Certainly
is considerably more helpful than just
Just looked over your code again. You are not running the qry
Wouldnt you need to do
qry.execute
?