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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute Stored Procedure from Command Button in ADP

Status
Not open for further replies.

ctwilliams

Programmer
Feb 15, 2002
86
US
I have setup a Data Access Page, and can't figure out how to execute a stored procedure by clicking on a command button.

I setup my onclick event handler like this...

Code:
<SCRIPT LANGUAGE=vbscript FOR=Command0 EVENT=onclick>
<!--
-->
</SCRIPT>

But what goes inside? Can I execute the stored procedure via some type of ADO command?
 
Here is an example of what the ADO code could look like. This code is from an Access Form.

Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rst As New ADODB.Recordset
Dim param1 As Parameter, param2 As Parameter
begDate = #10/1/2001#
endDate = #10/31/2001#

' Connect
Set cnn = CurrentProject.Connection

Set cmd.ActiveConnection = cnn
Set param1 = cmd.CreateParameter(&quot;Input&quot;, adDBDate, adParamInput)
cmd.Parameters.Append param1
param1.Value = begDate
Set param2 = cmd.CreateParameter(&quot;Input&quot;, adDBDate, adParamInput)
cmd.Parameters.Append param2
param2.Value = endDate

' Set up a command object for the stored procedure.
cmd.CommandText = &quot;dbo.sp_employeeRevenueProgress&quot;
cmd.CommandType = adCmdStoredProc

' Execute command to run stored procedure
''cmd.Execute

Set rst = cmd.Execute
 
Thanks! I finally got it to work by doing this...

Code:
<SCRIPT LANGUAGE=vbscript FOR=Command0 EVENT=onclick event=Current(oEventInfo) for=MSODSC>
<!--

Dim Con
Dim Rst

Set Con = CreateObject(&quot;ADODB.Connection&quot;)
Set Rst = CreateObject(&quot;ADODB.Recordset&quot;)

Con.open (&quot;provider=sqloledb.1;user id=xxx;password=xxx;initial catalog=xxx;data source=xxx&quot;)
Rst.Open &quot;MyStoredProc&quot;, Con

Rst.Close
Con.Close

-->
</SCRIPT>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top