woody wrote:
I have a bit of a newbie question (basically stated in the subject of
the posting). If need to get some data out of a SQL Server Database.
Can I use a control from a form to supply a parameter. I've created a
stored procedure with the parameter I need, I just dont know how to
send the data from the form to the SPT query.
So I need to get data out of [Forms]![Form1]![Combo6] to my SPT query.
Can I do it?
Any help is greatly appreciated.
Thanks!
Assuming you want [Forms]![Form1]![Combo6] to be a numeric parameter of
your pass through query, you can use code such as this to create the
query QRY_PASS_THROUGH:
Dim db As DAO.Database
Dim qdExtData As QueryDef
Dim strSQL As String
Set db = CurrentDb
strSQL = "SELECT * FROM TBL WHERE FIELD1 = " &
[Forms]![Form1]![Combo6]
Set qdExtData = db.CreateQueryDef("QRY_PASS_THROUGH")
qdExtData.Connect = "ODBC;DSN=???;UID=???;PWD=???;DBQ=???;"
qdExtData.SQL = strSQL
qdExtData.Close
db.Close
Set db = Nothing
The connect string parameters (???) depend upon the data source you are
connecting to.
HTH