how to code a button to export results of stored procedure to excel file

Joined
Sep 8, 2014
Messages
1
Reaction score
0
I've begun setting up a module for a click event. I'm wanting to click a button and have it export the results of a stored procedure called "usp_IssueTrackingGetPastDueIssues". I am having a hard time finding info on how to code this I am fairly new to vba. Any help would be greatly appreciated below is the module I have begun setting up.

Private Sub cmdExcel_Click()

Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sSql As String
Dim xlApp As New Excel.Application
Dim wbk As Excel.Workbook
Dim wksht As Excel.Worksheet


Set db = New ADODB.Connection
db.ConnectionString = "PROVIDER=SQLNCLI10;SERVER=SVBKSA69901M2W\IKM_QA;DATABASE=RiskControl;TRUSTED_CONNECTION=yes;"
db.Open

sSql = "usp_IssueTrackingGetPastDueIssues"

db.Execute sSql


db.Close
Set db = Nothing


Exit Sub
CleanExit:
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top