Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass parameters to pass-through query 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I want to use a pass-through query to execute a SQL stored procedure. Simple enough in itself, but I want to get user-supplied parameters into the pass-through query as it runs

eg the query looks like
EXECUTE spTest1 @AreaCode = 124

I want the user to supply the area-code in a form control - how do I write the code to get the supplied value into the query before it runs?
 
This code should do what you are after:

Code:
Dim cmd As ADODB.Command
Dim prm As ADODB.Parameter

Set cmd = New ADODB.Command
cmd.ActiveConnection = adoCN
cmd.CommandText = "[StoredProc Name Here]"
cmd.CommandType = adCmdStoredProc
Set prm = cmd.CreateParameter("AreaCode", adInteger, adParamInput, , Me!AreaCode)
cmd.Parameters.Append prm

cmd.Execute
        
Set prm = Nothing
Set cmd = Nothing

Just put your Stored Proc name in and away you go.

Oh and you will have to set your connection string to your server as well, I have mine in adoCN for ease of use.

Hope this is what you are after.

Regards
Simon ----------------------------------------
Of all the things I have lost in my life, the thing I miss the MOST is my mind!
----------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top