executing a job from Access Data Project

I would like to accomplish the following in Microsoft Access Project

Created a list box, which holds all the current jobs in SQL Server.

I want to  add a command button ,which on  clicking will execute the selected job by
executing the stored procedure sp_startjob .

Is this possible? Are there any examples that i can look at?

Who is Participating?
I believe the parameter name you're looking for is called job_name.  Or you can use job_id.

As long as the user has the appropriate permissions, you can use this vb code:

currentproject.execute "EXEC sp_startjob ..."


aswam1975Author Commented:
This is what i have done so far:
I have a list called displayJobs.Added a command button called Start Job.To the click  event i have the following.

However i get an error that says " Run time error 3701. Parameter object is improperly defined.
Inconsistent or incorrect information is provided".

The error is at line  .Parameters.Append prm. Can someone point out what i am doing wrong.

Private Sub startJob_Click()

      Dim rst As ADODB.Recordset
      Dim cmd As ADODB.Command
      Dim prm As ADODB.Parameter
      Dim job As String
      Dim numb As Integer

          Set cmd = New ADODB.Command
      numb = displayJobs.ListIndex
          job = displayJobs.ItemData(displayJobs.ListIndex)

      Set prm = New ADODB.Parameter
      prm.Name = "job"
      prm.Type = adVarChar
      prm.Direction = adParamInput
      prm.Value = job
      Set cmd = New ADODB.Command
      With cmd
          .ActiveConnection = CurrentProject.Connection
          .CommandText = "sp_start_job"
          .CommandType = adCmdStoredProc
          .Parameters.Append prm
      End With

         Set prm = Nothing
                Set cmd = Nothing

End Sub
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.