Closed Thread
Results 1 to 5 of 5

Insert stored procedure within excel vba

  1. #1
    Registered User
    Join Date
    09-10-2012
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    86

    Lightbulb Insert stored procedure within excel vba

    I created a form in excel with button and listbox. Once you click a button, I have the below code which connects to a SQL database and returns values in a excel list box with the execution of a SQL statement . what i would like to do is instead of using the SQL i want to run a stored procedure instead, i would replace the SQL with SP_GET_INFO . here is the current code. Any help would be appreciated

    Private Sub cmbList_Click()
    Dim conn As New ADODB.Connection
    Dim myRecSet As New ADODB.Recordset
    Dim SQL As String




    With conn
    .Provider = "SQLOLEDB"
    .Properties("Prompt") = adPromptAlways
    .ConnectionString = "Data Source=someserver\SQLEXPRESS; " & _
    "Initial Catalog=some catalog;"
    On Error Resume Next
    .Open
    If Err.Number <> 0 Then
    MsgBox ("You have elected to cancel this request"), vbOKOnly
    Exit Sub
    End If
    On Error GoTo 0
    End With

    SQL = "select TR_name, TR_Id, TR_Date from TBL_Employee WHERE TR_Status = '" & frmOrg_ID.cmbSelection & "' and TR_DRE > '2012-04-01' order by TR_Org_Id desc"


    myRecSet.Open SQL, conn
    If Not myRecSet.EOF Then
    Me.ListBox1.Column = myRecSet.GetRows


    End If



    End Sub

  2. #2
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Insert stored procedure within excel vba

    Go to VBA project and select the worksheet you want
    Select worksheet from the lefthand side listbox (=>worksheet) and the right hand side listbox will give you buttonless options like ON ACTIVATE or ON DEACTIVATE, etc
    Then just call your code from within that option[/LIST]

  3. #3
    Registered User
    Join Date
    09-10-2012
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    86

    Re: Insert stored procedure within excel vba

    i need to insert the STORED PROCEDURE INSTEAD OF THE SQL STATEMENT. It as to go in the code not a worksheet

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Insert stored procedure within excel vba

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Insert stored procedure within excel vba

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Thread Closed.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1