Article ID: 124391
Article Last Modified on 1/19/2007
Function ExecuteSPT (sqltext As String, connectstring As String)
' Purpose: Run a temporary pass-through query.
' Accepts: sqltext: SQL string to run.
' connectstring: Connection string, which must be at least
' "ODBC;".
' Returns: nothing.
Dim mydb As Database, myq As QueryDef
Set mydb = DBEngine.Workspaces(0).Databases(0)
' Create a temporary QueryDef object that is not saved.
Set myq = mydb.CreateQueryDef("")
' Set the ReturnsRecords property to False in order to use the
' Execute method.
myq.returnsrecords = False
myq.connect = connectstring
myq.sql = sqltext
myq.Execute
myq.Close
End Function
To run a stored procedure called sp_example on your SQL Server, you could
type the following line in the Debug window (or Immediate window in version
2.0):
?ExecuteSPT("sp_example","ODBC;")
Note that this code accepts SQL statements that are specific to the server
that you are using. Please refer to your server's documentation to
determine valid SQL statements for your server.
Keywords: kbinfo kbprogramming kbusage KB124391