If you are familiar with Dynamics SL Customization Mode you may know how to add a button to a screen. But do you know how to run a stored procedure from that button?
In Customize Mode go to the Visual Basic Editor. You need to add code to run the stored procedure.
Here is the code to do this. It calls a stored procedure in SQL on the ODBC connection listed and passes three parameters from the User fields located on the screen.
Private Sub Button1_Click()
Set pConnection = CreateObject("ADODB.Connection")
Call pConnection.open("MyODBC", "SQL_User", "mypwd")
'Passes company ID
sSQL = "EXEC mystoredproc '" + GetObjectValue("xuser1") + "', '" + _
GetObjectValue("xUser2") + "', '" + GetObjectValue("xUser3") + "'"
MsgBox sSQL
Call pConnection.Execute(sSQL)
Call pConnection.Close
MsgBox "Your stored procedure is done!"
End Sub
There's a lot more you can do here, like error trapping and the like, but this should get you started.
No comments:
Post a Comment