Article ID: 131534
Article Last Modified on 1/19/2007
182568 ACC97: Microsoft Access 97 Sample Queries Available in Download Center
Option Explicit
Function ParamSPT (NewGroup As String)
Dim MyDb As Database, MyQ As QueryDef
Set MyDb = CurrentDB()
' Create a temporary QueryDef object that is not saved.
Set MyQ = MyDb.CreateQueryDef("")
' Type a connect string using the appropriate values for your
' server.
MyQ.connect = "ODBC;DSN=dsn1;UID=<username>;PWD=<strong password>;DATABASE=test"
' Set ReturnsRecords to false in order to use the Execute method.
MyQ.returnsrecords = False
' Set the SQL property and concatenate the variables.
MyQ.sql = "sp_addgroup" & " " & NewGroup
Debug.Print MyQ.sql
MyQ.Execute
MyQ.Close
MyDb.Close
End Function
? ParamSPT("TESTERS")
Option Explicit
Function ParamSPT2(MyParam As String)
Dim MyDb As Database, MyQry As QueryDef, MyRS As Recordset
Set MyDb = CurrentDB()
Set MyQry = MyDb.CreateQueryDef("")
' Type a connect string using the appropriate values for your
' server.
MyQry.connect = "ODBC;DSN=user1;UID=user1;PWD=user1;DATABASE=TEST"
' Set the SQL property and concatenate the variables.
MyQry.SQL = "sp_server_info " & MyParam
MyQry.ReturnsRecords = True
Set MyRS = MyQry.OpenRecordset()
MyRS.MoveFirst
Debug.Print MyRS!attribute_id, MyRS!attribute_name, _
MyRS!attribute_value
MyQry.Close
MyRS.Close
MyDb.Close
End Function
? ParamSPT2("500")
128408 ACC: How to Return Values from SQL Stored Procedures
Additional query words: spt
Keywords: kbhowto kbprogramming kbusage KB131534