mercredi 1 avril 2015

Excel VB- Macros:

I have a stored procedure which has 4 input parameters.



@Scenario, @StockID, @EOD, @EOD_PREV.


Based on the @Scenario (total 9 Scenarios), different SQL scripts are executed.


My requirement is: I need to use VB Macros to display results in each worksheet, I need to use one ActiveX-Command button to run all the Scenarios. Each Scenario in a separate Worksheet.


So far, I have managed to create individual connections for each sheet and Active X Command Button for each sheet.


Below is the query that I used.



Private Sub CommandButton1_Click()
Dim Scenario As String
Dim STOCK_ID As String
Dim EOD As String
Dim EOD_PREV As String
Scenario = Sheets("Stocks").Range("B3").Value
STOCK_ID = Sheets("Stocks").Range("B8").Value
EOD = Sheets("Stocks").Range("B6").Value
EOD_PREV = Sheets("Stocks").Range("B7").Value
With ActiveWorkbook.Connections("9").OLEDBConnection
.CommandText = "EXEC dbo.usp_Inventory_Reconcilliation '" & Scenario & "','" &
STOCK_ID & "', '" & EOD & "' ,'" & EOD_PREV & "'"
ActiveWorkbook.RefreshAll
End With
End Sub


Can somebody help me out with this situation.


Aucun commentaire:

Enregistrer un commentaire