Article ID: 184749
Article Last Modified on 6/29/2004
MyDb.Execute "sp_name", dbSQLPassThrough
i = MyDb.RowsAffected
You can also use ExecuteSQL:
i = MyDb.ExecuteSQL("sp_name")
However, this syntax is obsolete, and you should replace it with the
Execute method and RowsAffected property syntax given at the beginning
of this section.
Delete Authors where name like "fred%"
Using Execute with an SQL statement that uses "SELECT..." returns
records that causes a run-time error.
Data1.Options = dbSQLPassThrough
Data1.Recordsource = "sp_name" ' Name of the stored procedure.
Data1.Refresh ' Refresh the data control.
When you use the SQLPassThrough bit, the Microsoft Jet database engine
ignores the syntax used and passes the command through to the SQL
server.
Dim Rs as Recordset
' Open your desired database here.
Set MyDB = DBEngine.Workspaces(0).OpenDatabase(...
Set Rs = MyDB.OpenRecordset("sp_name", dbOpenSnapshot, _
dbSQLPassThrough)
You must use dbOpenSnapshot. dbOpenDynaset and dbOpenTable do not
apply to pass-through queries.
' String specifying SQL.
SQL = "My_StorProc parm1, parm2, parm3"
...
' For a stored procedure that doesn't return records.
MyDb.Execute SQL, dbSQLPassThrough
i = MyDb.RowsAffected
...
'For a stored procedure that returns records.
set Rs = MyDB.OpenRecordset(SQL, dbOpenSnapshot, dbSQLPassThrough)
The object variable (Rs) contains the first set of results from the
stored procedure (My_StorProc).
Dim db as Database
Dim l as Long
Dim Rs as Recordset
Set Db = DBEngine.Workspaces(0).OpenDatabase _
("", False, False, "ODBC;dsn=yourdsn;uid=youruid;pwd=yourpwd:")
' For SPs that don't return rows.
Db.Execute "YourSP_Name", dbSQLPassThrough
l = Db.RowsAffected
' For SPs that return rows.
Set Rs = Db.OpenRecordset("YourSP_Name", dbOpenSnapshot, _
dbSQLPassThrough)
Col1.text = Rs(0) ' Column one.
Col2.text = Rs!ColumnName
Col3.Text = Rs("ColumnName")
Microsoft SQL Server "Microsoft SQL Server Programmer's Reference for Visual Basic," version 4.2, pages 200-201
Additional query words: kbODBC kbVBp500 kbVBp600 kbVBp400 kbdse kbDSupport kbVBp
Keywords: kbhowto KB184749