Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

call stored procedure with a passthru query

Status
Not open for further replies.

abenitez77

IS-IT--Management
Oct 18, 2007
147
US
I am trying to call a stored procedure with a passthru query but it is not working for me. I get Run-time error '3146':
ODBC --call failed.

strconn = "ODBC;DRIVER={SQL Server Native Client 10.0};SERVER=UKHOST04;DATABASE=CoOpClaimConceptReferenceTables;TRUSTED_CONNECTION=Yes;"

mysproc = "exec dbo.RecalculateScan 110300032"

Call SQL_PassThrough(strconn, mysql)

Function SQL_PassThrough(ByVal ConnectionString As String, _
ByVal strsql As String, _
Optional ByVal QueryName As String)

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef

Set dbs = CurrentDb
dbs.QueryTimeout = 1800

Set qdf = dbs.CreateQueryDef
With qdf
.name = QueryName
.Connect = ConnectionString
sql = strsql
.sql = sql
.ODBCTimeout = 1800
.ReturnsRecords = (Len(QueryName) > 0)
If .ReturnsRecords = False Then
.Execute
Else 'A query of QueryName must be manually created first time or this will error out.

For Each qdf In dbs.QueryDefs
If qdf.name = QueryName Then
dbs.QueryDefs.Delete QueryName
Exit For
End If
Next

Set qdf = dbs.CreateQueryDef(QueryName, sql)

End If
.Close
End With
Set qdf = Nothing
dbs.Close
Set dbs = Nothing

End Function

 
Found the answer myself...my connection string had the wrong db, the code was fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top