http://www.functionx.com/vbaccess/Lesson22.htm

Index

Stored Procedures

 

You can create a procedure and save it as an object. Although you may use the event of a button, a form, or another control to create the procedure, the object or control doesn't own the procedure. In fact, after creating the procedure, it becomes an object and you can access it from anywhere in the database. Also, the procedure is saved as an object (as done for a table, a query, or a form) and it is stored in the database. Because the procedure is stored as an object, it is referred to as a stored procedure.

Like a view, a stored procedure is not represented in the Database window. This means that, after creating, you should be aware of its existence or you should find a way to know what stored procedures are available in your database.

 

 

Private Sub cmdCreateProcedureChangeTableSSK_Click()

    Dim conEmployees As ADODB.Connection

    Dim strProcedure As String

    Dim strProcedure2 As String

    Dim strProcedure3 As String

   

    Set conEmployees = Application.CurrentProject.Connection

    strProcedure = "CREATE PROCEDURE SetNewMinSalary11 " & _

                    "(NewMinSalary Currency) " & _

                   "AS " & _

                   "Update tblSSK " & _

                   "SET tip = NewMinSalary " & _

                   "WHERE tip < NewMinSalary;"

   

    conEmployees.Execute strProcedure

    conEmployees.Close

 

End Sub

------------------------------------------------------------------------------------------

Private Sub cmdExecuteProcedure_Click()

 

    Dim conEmployees As ADODB.Connection

    Dim strProcedure As String

   

    Set conEmployees = Application.CurrentProject.Connection

    strProcedure = "EXECUTE SetNewMinSalary11 56;"

   

    conEmployees.Execute strProcedure

    conEmployees.Close

 

End Sub