Article ID: 112108
Article Last Modified on 1/18/2007
182568 ACC97: Microsoft Access 97 Sample Queries Available in Download Center
Option Explicit
Function CreateSPT (SPTQueryName As String, SQLString As String, _
ConnectString As String)
'-----------------------------------------------
' FUNCTION: CreateSPT()
' PURPOSE:
' Creates an SQL pass-through query using the supplied arguments:
' SPTQueryName: the name of the query to create
' SQLString: the query's SQL string
' ConnectString: the ODBC connect string, this must be at
' least "ODBC;"
'-----------------------------------------------
Dim mydatabase As Database, myquerydef As QueryDef
Set mydatabase = DBENGINE.Workspaces(0).Databases(0)
Set myquerydef = mydatabase.CreateQueryDef(SPTQueryName)
myquerydef.connect = ConnectString
myquerydef.sql = SQLString
myquerydef.Close
End Function
? CreateSPT("MySptQuery", "sp_help", "ODBC;")
? CreateSPT("Test", "Select * from authors",_
"ODBC;DSN=Red;Database=Pubs;USID=JOE;PWD=JOE")
in the Debug window (or Immediate window in version 2.0). This example also
includes the UserId and password (both "Joe") arguments in the ODBC connect
string. Note that if you do not supply at least "ODBC;" as the connect
string, you receive the following error message:
Additional query words: spt
Keywords: kbfaq kbhowto kbprogramming kbusage KB112108