Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. Dim datatype As Single
  2. datatype = DataTypeBox.Value
  3. Dim year As Single
  4. year = ForecastYearBox.Value
  5. Dim cnPubs As ADODB.Connection
  6. Set cnPubs = New ADODB.Connection
  7. Dim rsPubs As ADODB.Recordset
  8. Set rsPubs = New ADODB.Recordset
  9.  
  10. cnPubs.Open strConn
  11.  
  12. Set cmd = New ADODB.Command
  13. cmd.ActiveConnection = cnPubs
  14. cmd.CommandType = adCmdStoredProc
  15. cmd.CommandText = "CM.Proc_CashFlowForecast"
  16. cmd.CommandTimeout = 7200 'Seconds
  17.  
  18. Call cmd.Execute(Parameters:=Array(year, datatype), Options:=adCmdStoredProc)
  19.  
  20. With rsPubs
  21. ' Assign the Connection object.
  22. .ActiveConnection = cnPubs
  23. ' Extract the required records.
  24. .Open "SELECT * FROM AnalyticsV2.dbo.CashFlowForecast"
  25. ' Copy the records into cell A1 on Sheet1.
  26. If dataype = 12 Then
  27. Sheet1.Range("A2").CopyFromRecordset rsPubs
  28. ElseIf dataype = 3 Then
  29. Sheet2.Range("A2").CopyFromRecordset rsPubs
  30. End If
  31.  
  32. .Close
  33. End With
  34.  
  35. cnPubs.Close
  36. Set rsPubs = Nothing
  37. Set cnPubs = Nothing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement